diff options
| author | nytpu <alex@nytpu.com> | 2021-05-11 11:16:26 -0600 |
|---|---|---|
| committer | nytpu <alex@nytpu.com> | 2021-05-11 11:22:17 -0600 |
| commit | cc5c8b2f23854c7c787d553242818d4aaea0da71 (patch) | |
| tree | 462f0a8c4d9c0155e96727125e724b200410a41d /comitium.go | |
| parent | 244746dff7eabd89720688b835cfe803372d91ef (diff) | |
add getLang() to parse language
Diffstat (limited to 'comitium.go')
| -rw-r--r-- | comitium.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/comitium.go b/comitium.go index 41cd616..681b6fb 100644 --- a/comitium.go +++ b/comitium.go @@ -13,11 +13,17 @@ import ( "path/filepath" "github.com/mitchellh/go-homedir" + "golang.nytpu.com/comitium/localizations" + "golang.org/x/text/language" "golang.nytpu.com/comitium/core" "golang.nytpu.com/comitium/fetch" ) +var supportedLangs = []language.Tag{ + language.AmericanEnglish, // en-US (fallback) +} + func main() { argCheck(os.Args, 2, true, "Please provide a command.") @@ -41,6 +47,9 @@ func main() { c.AddFlagSet(globalFs) c.Parse(os.Args[2:]) + // figure out what language to use + localizer := getLang() + // dataPath is the location where all the data (list of subs, cached hashes, // etcetera) are stored dataPath := getDataPath() @@ -152,6 +161,18 @@ func getDataPath() string { return verifyPath("comitium") } +// getLang will return the localizer for the user's lang +func getLang() *localizations.Localizer { + matcher := language.NewMatcher(supportedLangs) + var lang language.Tag + if *langFlag != "" { + lang, _ = language.MatchStrings(matcher, *langFlag) + } else if env := os.Getenv("LANG"); env != "" { + lang, _ = language.MatchStrings(matcher, env) + } + return localizations.New(lang.String(), supportedLangs[0].String()) +} + func usage() { fmt.Fprintf(os.Stderr, "Usage:\n") fmt.Fprintf(os.Stderr, " %v <command> [FLAGS] [ARGUMENTS]\n\n", os.Args[0]) |
