MCPcopy Create free account
hub / github.com/MMadmer/EpicAssetsNotifyBot / NormalizeLocale

Method NormalizeLocale

internal/model/normalize.go:211–236  ·  view source on GitHub ↗

NormalizeLocale returns the canonical locale code or an empty string.

(locale string)

Source from the content-addressed store, hash-verified

209
210// NormalizeLocale returns the canonical locale code or an empty string.
211func (n Normalizer) NormalizeLocale(locale string) string {
212 candidate := strings.TrimSpace(strings.ReplaceAll(locale, "_", "-"))
213 if candidate == "" {
214 return ""
215 }
216
217 aliases := make(map[string]string, len(n.locales)*4)
218 for _, code := range n.sortedLocaleCodes() {
219 name := n.locales[code]
220 normalizedCode := strings.ToLower(code)
221 aliases[normalizedCode] = code
222 aliases[strings.ReplaceAll(normalizedCode, "-", "")] = code
223
224 short := strings.ToLower(strings.SplitN(code, "-", 2)[0])
225 if _, ok := aliases[short]; !ok {
226 aliases[short] = code
227 }
228
229 normalizedName := strings.ToLower(strings.TrimSpace(name))
230 if normalizedName != "" {
231 aliases[normalizedName] = code
232 }
233 }
234
235 return aliases[strings.ToLower(candidate)]
236}
237
238func (n Normalizer) sortedLocaleCodes() []string {
239 codes := make([]string, 0, len(n.locales))

Callers 1

Calls 1

sortedLocaleCodesMethod · 0.95

Tested by

no test coverage detected