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)
| 66 | // code>" for all non-Chinese languages. For Chinese, it will return |
| 67 | // "zh-<script>", defaulting to "hant" if script is unspecified. |
| 68 | func 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 | |
| 86 | func determineLocale(reader LocaleReader) (string, error) { |
| 87 | locale := reader.Locale() |
no test coverage detected