Skip to content

Commit aa1824e

Browse files
migrated language definitions to project root
1 parent c2cfac0 commit aa1824e

5 files changed

Lines changed: 9 additions & 6 deletions

File tree

locales/locales.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package locales
2+
3+
import "embed"
4+
5+
//go:embed *.yaml
6+
var LocaleFS embed.FS

ui/i18n/i18n.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
package i18n
99

1010
import (
11-
"embed"
1211
"fmt"
1312
"path" // Use the 'path' package for consistent forward slashes
1413
"strings"
1514

1615
"github.com/nicksnyder/go-i18n/v2/i18n"
16+
"github.com/toeirei/keymaster/locales"
1717
"golang.org/x/text/language"
1818
"golang.org/x/text/language/display"
1919
"gopkg.in/yaml.v3"
2020
)
2121

22-
//go:embed locales/*.yaml
23-
var localeFS embed.FS
24-
2522
var (
2623
bundle *i18n.Bundle
2724
localizer *i18n.Localizer
@@ -43,7 +40,7 @@ func Init(defaultLang string) {
4340
availableLocales = make(map[string]string)
4441

4542
// Discover and load all locale files from the embedded filesystem.
46-
files, err := localeFS.ReadDir("locales")
43+
files, err := locales.LocaleFS.ReadDir("locales")
4744
if err != nil {
4845
// This should not happen with a valid embed.
4946
panic(fmt.Sprintf("failed to read embedded locales directory: %v", err))
@@ -73,7 +70,7 @@ func Init(defaultLang string) {
7370

7471
// Load the file into the bundle
7572
filePath := path.Join("locales", fileName)
76-
_, err := bundle.LoadMessageFileFS(localeFS, filePath)
73+
_, err := bundle.LoadMessageFileFS(locales.LocaleFS, filePath)
7774
if err != nil {
7875
panic(fmt.Sprintf("failed to load locale file %s: %v", fileName, err))
7976
}

0 commit comments

Comments
 (0)