Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-14 02:22:42 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-14 19:56:31 +0300
commit10025ffa66c011fd756af780772260d833460795 (patch)
tree0cf2d3924f3a8c26d47c4d9fe20d2438b7c4b6fc /web/locale
parent5ee62b25ca9a3bf0ce683adbba5b1b64ddea074e (diff)
Subscription
Diffstat (limited to 'web/locale')
-rw-r--r--web/locale/locale.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/web/locale/locale.go b/web/locale/locale.go
index cdfe5394..8d4179ae 100644
--- a/web/locale/locale.go
+++ b/web/locale/locale.go
@@ -48,6 +48,22 @@ func InitLocalizer(i18nFS embed.FS, settingService SettingService) error {
return nil
}
+// InitLocalizerFS allows initializing i18n from any fs.FS (e.g., disk), rooted at a directory containing a "translation" folder
+func InitLocalizerFS(fsys fs.FS, settingService SettingService) error {
+ // set default bundle to english
+ i18nBundle = i18n.NewBundle(language.MustParse("en-US"))
+ i18nBundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
+
+ if err := parseTranslationFiles(fsys, i18nBundle); err != nil {
+ return err
+ }
+
+ if err := initTGBotLocalizer(settingService); err != nil {
+ return err
+ }
+ return nil
+}
+
func createTemplateData(params []string, seperator ...string) map[string]any {
var sep string = "=="
if len(seperator) > 0 {
@@ -118,8 +134,8 @@ func LocalizerMiddleware() gin.HandlerFunc {
}
}
-func parseTranslationFiles(i18nFS embed.FS, i18nBundle *i18n.Bundle) error {
- err := fs.WalkDir(i18nFS, "translation",
+func parseTranslationFiles(fsys fs.FS, i18nBundle *i18n.Bundle) error {
+ err := fs.WalkDir(fsys, "translation",
func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
@@ -129,7 +145,7 @@ func parseTranslationFiles(i18nFS embed.FS, i18nBundle *i18n.Bundle) error {
return nil
}
- data, err := i18nFS.ReadFile(path)
+ data, err := fs.ReadFile(fsys, path)
if err != nil {
return err
}