MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ParseLocale

Function ParseLocale

util/ui/i18n.go:68–84  ·  view source on GitHub ↗

ParseLocale will return a locale formatted as " - " for all non-Chinese languages. For Chinese, it will return "zh- ", defaulting to "hant" if script is unspecified.

(locale string)

Source from the content-addressed store, hash-verified

66// code>" for all non-Chinese languages. For Chinese, it will return
67// "zh-<script>", defaulting to "hant" if script is unspecified.
68func ParseLocale(locale string) (string, error) {
69 lang, err := language.Parse(locale)
70 if err != nil {
71 return "", err
72 }
73
74 base, script, region := lang.Raw()
75 switch base.String() {
76 case chineseBase:
77 if script.String() == unspecifiedScript {
78 return "zh-hant", nil
79 }
80 return strings.ToLower(fmt.Sprintf("%s-%s", base, script)), nil
81 default:
82 return strings.ToLower(fmt.Sprintf("%s-%s", base, region)), nil
83 }
84}
85
86func determineLocale(reader LocaleReader) (string, error) {
87 locale := reader.Locale()

Callers 4

IsSupportedLocaleFunction · 0.92
supportedLanguagesFunction · 0.92
i18n_test.goFile · 0.85
determineLocaleFunction · 0.85

Calls 2

ParseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected