diff --git a/docs/en-US/core/functions/locales/resolve-canonical-locale.mdx b/docs/en-US/core/functions/locales/resolve-canonical-locale.mdx new file mode 100644 index 00000000..e78a959a --- /dev/null +++ b/docs/en-US/core/functions/locales/resolve-canonical-locale.mdx @@ -0,0 +1,67 @@ +--- +title: resolveCanonicalLocale +description: API reference for the resolveCanonicalLocale function +--- + +## Overview + +The `resolveCanonicalLocale` function converts alias locale codes into their canonical locale codes when custom mapping is configured. This standalone function provides the same functionality as the GT class method without requiring an instance. + +It is the inverse operation of [`resolveAliasLocale`](/docs/core/functions/locales/resolve-alias-locale). + +--- + +## Reference + +### Parameters + + + +### Returns + +`string` - The canonical locale code if mapping exists, otherwise the original locale + +--- + +## Examples + +```typescript +import { resolveCanonicalLocale } from 'generaltranslation'; + +const customMapping = { + 'simplified-chinese': { code: 'zh-CN', name: 'Simplified Chinese' }, + 'traditional-chinese': { code: 'zh-TW', name: 'Traditional Chinese' } +}; + +// Resolve alias to canonical +console.log(resolveCanonicalLocale('simplified-chinese', customMapping)); // 'zh-CN' +console.log(resolveCanonicalLocale('traditional-chinese', customMapping)); // 'zh-TW' + +// Non-mapped locale returns original +console.log(resolveCanonicalLocale('es-ES', customMapping)); // 'es-ES' +``` +--- + +## Notes + +- Converts user-friendly aliases back to canonical locale codes +- Returns the original locale if no mapping exists +- Essential for normalizing locales before passing them to translation services +- Works with custom locale mappings +- Stateless function - no side effects + +## Next steps + +- Use GT class method [`resolveCanonicalLocale`](/docs/core/class/methods/locales/resolve-canonical-locale) +- Convert back to an alias with [`resolveAliasLocale`](/docs/core/functions/locales/resolve-alias-locale)