mirror of
https://github.com/siderolabs/image-factory.git
synced 2025-09-21 13:51:08 +02:00
Adds localization support with go-i18n module. Adds Russian language support in the frontend interface Signed-off-by: Aleksandr Gamzin <gamzin@altlinux.org> Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
33 lines
887 B
Go
33 lines
887 B
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package http
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
"golang.org/x/text/language"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func loadLocalizerBundle() (*i18n.Bundle, error) {
|
|
bundle := i18n.NewBundle(language.English)
|
|
bundle.RegisterUnmarshalFunc("yaml", yaml.Unmarshal)
|
|
|
|
entries, err := localesFS.ReadDir("locales")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read locales directory: %w", err)
|
|
}
|
|
|
|
for _, entry := range entries {
|
|
if _, err := bundle.LoadMessageFileFS(localesFS, filepath.Join("locales", entry.Name())); err != nil {
|
|
return nil, fmt.Errorf("failed to load translation file %s: %w", entry.Name(), err)
|
|
}
|
|
}
|
|
|
|
return bundle, nil
|
|
}
|