Convert a locale/language to a supported locale/language
Returns undefined if no supported locale is found
undefined
It will first try to find an exact match for a locale (not language). If not found, it will try:
import { convertToSupportedLocale } from "@pistonite/pure/pref";// suppose supported locales are ["en", "zh", "zh-CN"]console.log(convertToSupportedLocale("en")); // "en"console.log(convertToSupportedLocale("en-US")); // "en"console.log(convertToSupportedLocale("zh")); // "zh-CN"console.log(convertToSupportedLocale("zh-CN")); // "zh-CN"console.log(convertToSupportedLocale("zh-TW")); // "zh"console.log(convertToSupportedLocale("es")); // undefined Copy
import { convertToSupportedLocale } from "@pistonite/pure/pref";// suppose supported locales are ["en", "zh", "zh-CN"]console.log(convertToSupportedLocale("en")); // "en"console.log(convertToSupportedLocale("en-US")); // "en"console.log(convertToSupportedLocale("zh")); // "zh-CN"console.log(convertToSupportedLocale("zh-CN")); // "zh-CN"console.log(convertToSupportedLocale("zh-TW")); // "zh"console.log(convertToSupportedLocale("es")); // undefined
Convert a locale/language to a supported locale/language
Returns
undefined
if no supported locale is foundExample
It will first try to find an exact match for a locale (not language). If not found, it will try: