mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
fix(i18n): lint, review and clean up a little
This commit is contained in:
parent
775014c459
commit
cdb680ac1e
2 changed files with 10 additions and 4 deletions
2
Makefile
2
Makefile
|
@ -35,8 +35,10 @@ clean:
|
||||||
rm -rf $(BIN)
|
rm -rf $(BIN)
|
||||||
|
|
||||||
i18n_extract:
|
i18n_extract:
|
||||||
|
$(info ******************** extracting translation files ********************)
|
||||||
goi18n extract -outdir translations
|
goi18n extract -outdir translations
|
||||||
goi18n merge -outdir translations translations/*
|
goi18n merge -outdir translations translations/*
|
||||||
|
|
||||||
i18n_merge:
|
i18n_merge:
|
||||||
|
$(info ******************** merging translation files ********************)
|
||||||
goi18n merge -outdir translations translations/*
|
goi18n merge -outdir translations translations/*
|
||||||
|
|
12
localizer.go
12
localizer.go
|
@ -3,10 +3,11 @@ package cobra
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultLanguage = language.English
|
var defaultLanguage = language.English
|
||||||
|
@ -366,10 +367,13 @@ func detectLangs() []string {
|
||||||
|
|
||||||
func appendLang(langs *[]string, lang language.Tag) {
|
func appendLang(langs *[]string, lang language.Tag) {
|
||||||
langString := lang.String()
|
langString := lang.String()
|
||||||
langBase, _ := lang.Base()
|
|
||||||
*langs = append(*langs, langString)
|
*langs = append(*langs, langString)
|
||||||
*langs = append(*langs, langBase.ISO3())
|
|
||||||
*langs = append(*langs, langBase.String())
|
langBase, confidentInBase := lang.Base()
|
||||||
|
if confidentInBase != language.No {
|
||||||
|
*langs = append(*langs, langBase.String())
|
||||||
|
*langs = append(*langs, langBase.ISO3())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupLocalizer() {
|
func setupLocalizer() {
|
||||||
|
|
Loading…
Reference in a new issue