pure
    Preparing search index...

    Function convertToSupportedLocale

    • Convert a locale/language to a supported locale/language

      Returns undefined if no supported locale is found

      Example

      It will first try to find an exact match for a locale (not language). If not found, it will try:

      • the first supported locale with a matching language
      • the first supported language
      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

      Parameters

      • newLocale: string

      Returns undefined | string