Skip to content

Feature Request: Add function to return locale that's currently used by the library #82

@kaladivo

Description

@kaladivo

Description

Let's say your app supports english and german language. User with czech locale logs in and the app fallbacks to english.

Currently, if you setup i18n like this:

export const i18n = new I18n(
  enableHiddenFeatures
    ? translations
    : {
        en:  translations.en,
        de: translations.de,
      }
)
i18n.locale = 'cs'
i18n.defaultLocale = 'en'
i18n.enableFallback = true

i18n.locale returns "cs" despite en translations being used.

Describe the solution

Add function getUsedLocale() that will return locale that is currently used by the library.

Alternatives you considered

In my example above, we can test keys(translations).include(I18n.locale), but parsing language code is not that straight forward usually it might be in format like da_DK or de_DE. This logic is already included in the library and it does not seem right to duplicate it to find out what language is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions