i18n
i18n copied to clipboard
Example using Go Embed.FS
Thanks for this great library, I put together an example of how to use it with Go 1.16 embed.FS:
package locales
import (
"embed"
)
//go:embed */*.yml
var translations embed.FS
func I18n() (*i18n.I18n, error) {
// assuming embedded files at ./en/*.yml
return i18n.New(i18n.Assets(translationNames, translations.ReadFile), "en")
}
func translationNames() (filenames []string) {
fs.WalkDir(translations, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
filenames = append(filenames, path)
return nil
})
return filenames
}