Function preferredLocale

  • Get the user's preferred locale from the environment

    Parameters

    • fallback: string

      The default locale to use when no locales are matched to the user's environment. This should be one of the appLocales array values

    • appLocales: string[]

      An array of locales supported by the app

    • Optional options: PreferredLocaleOptions = {}

      Options for the function

    Returns string

    The user's preferred locale

    Example

    import { preferredLocale } from 'preferred-locale'

    preferredLocale('en-US', ['en-US', 'fr-FR', 'de-DE', 'az-Cyrl-AZ']) // 'en-US'

    preferredLocale('en-US', ['en-US', 'fr-FR', 'de-DE', 'az-Cyrl-AZ'], {
    regionLowerCase: true
    }) // 'en-us'

    preferredLocale('en', ['en', 'fr', 'de', 'az'], {
    languageOnly: true
    }) // 'en'