MCPcopy
hub / github.com/lingodotdev/lingo.dev / resolveLocaleCode

Function resolveLocaleCode

packages/spec/src/locales.ts:271–287  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

269 * @throws {Error} If the provided locale code is invalid.
270 */
271export const resolveLocaleCode = (value: string): LocaleCodeFull => {
272 const existingFullLocaleCode = Object.values(localeMap)
273 .flat()
274 .includes(value as any);
275 if (existingFullLocaleCode) {
276 return value as LocaleCodeFull;
277 }
278
279 const existingShortLocaleCode = Object.keys(localeMap).includes(value);
280 if (existingShortLocaleCode) {
281 const correspondingFullLocales = localeMap[value as LocaleCodeShort];
282 const fallbackFullLocale = correspondingFullLocales[0];
283 return fallbackFullLocale;
284 }
285
286 throw new Error(`Invalid locale code: ${value}`);
287};
288
289/**
290 * Determines the delimiter used in a locale code

Callers 3

locales.spec.tsFile · 0.90
init.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected