Skip to content

Commit 14483ac

Browse files
committed
fix: WalkLocales
1 parent 56d7009 commit 14483ac

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

modules/options/base.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ func Labels(name string) ([]byte, error) {
3838
return fileFromDir(path.Join("label", name))
3939
}
4040

41+
// WalkLocales reads the content of a specific locale from static or custom path.
42+
func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) error) error {
43+
for _, v := range pathsForWalkLocales() {
44+
if err := walkAssetDir(v, callback); err != nil && !os.IsNotExist(err) {
45+
return fmt.Errorf("failed to walk locales. Error: %w", err)
46+
}
47+
}
48+
return nil
49+
}
50+
4151
func walkAssetDir(root string, callback func(path, name string, d fs.DirEntry, err error) error) error {
4252
if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
4353
// name is the path relative to the root

modules/options/dynamic.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package options
77

88
import (
99
"fmt"
10-
"io/fs"
1110
"os"
1211
"path"
1312
"path/filepath"
@@ -60,16 +59,11 @@ func Dir(name string) ([]string, error) {
6059
return directories.AddAndGet(name, result), nil
6160
}
6261

63-
// WalkLocales reads the content of a specific locale from static or custom path.
64-
func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) error) error {
65-
if err := walkAssetDir(filepath.Join(setting.StaticRootPath, "options", "locale"), callback); err != nil && !os.IsNotExist(err) {
66-
return fmt.Errorf("failed to walk locales. Error: %w", err)
62+
func pathsForWalkLocales() []string {
63+
return []string{
64+
filepath.Join(setting.StaticRootPath, "options", "locale"),
65+
filepath.Join(setting.CustomPath, "options", "locale"),
6766
}
68-
69-
if err := walkAssetDir(filepath.Join(setting.CustomPath, "options", "locale"), callback); err != nil && !os.IsNotExist(err) {
70-
return fmt.Errorf("failed to walk locales. Error: %w", err)
71-
}
72-
return nil
7367
}
7468

7569
// fileFromDir is a helper to read files from static or custom path.

modules/options/static.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package options
88
import (
99
"fmt"
1010
"io"
11-
"io/fs"
1211
"os"
1312
"path"
1413
"path/filepath"
@@ -69,12 +68,10 @@ func AssetDir(dirName string) ([]string, error) {
6968
return results, nil
7069
}
7170

72-
// WalkLocales reads the content of a specific locale from static or custom path.
73-
func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) error) error {
74-
if err := walkAssetDir(filepath.Join(setting.CustomPath, "options", "locale"), callback); err != nil && !os.IsNotExist(err) {
75-
return fmt.Errorf("failed to walk locales. Error: %w", err)
71+
func pathsForWalkLocales() []string {
72+
return []string{
73+
filepath.Join(setting.CustomPath, "options", "locale"),
7674
}
77-
return nil
7875
}
7976

8077
// fileFromDir is a helper to read files from bindata or custom path.

0 commit comments

Comments
 (0)