Creation:2024-08-11Last update:2025-06-29
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
This doc is out of date, the base version has been updated on 23 August 2025.
Go to English docVersion History
- "Initial history"v5.5.1029/06/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishEdit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
Documentation: getLocaleLang Function in intlayer
Description
The getLocaleLang function extracts the language code from a locale string. It supports locales with or without country codes. If no locale is provided, it defaults to returning an empty string.
Parameters
locale?: Locales- Description: The locale string (e.g.,
Locales.ENGLISH_UNITED_STATES,Locales.FRENCH_CANADA) from which the language code is extracted. - Type:
Locales(optional)
- Description: The locale string (e.g.,
Returns
- Type:
string - Description: The language code extracted from the locale. If the locale is not provided, it returns an empty string (
'').
Example Usage
Extracting Language Codes:
Edge Cases
No Locale Provided:
- The function returns an empty string when
localeisundefined.
- The function returns an empty string when
Malformed Locale Strings:
- If the
localedoes not follow thelanguage-countryformat (e.g.,Locales.ENGLISH-US), the function safely returns the part before'-'or the entire string if no'-'is present.
- If the