Class LocaleState
-
Constructor Summary
ConstructorsConstructorDescriptionLocaleState(Context applicationContext, String sourceLocale, String[] appLocales, Locale currentLocale) Creates a LocaleState instance. -
Method Summary
Modifier and TypeMethodDescriptionString[]The app's supported locales, including the source locale.The current locale as provided by Android or the the locale set usingsetCurrentLocale(Locale).The resolved locale is one of the app locales that best matches the current locale.The source locale.String[]The app's supported locales without the source locale.booleanReturnstrueif the source locale matchesthe resolved locale.voidsetCurrentLocale(Locale currentLocale) Set the locale used in the app.
-
Constructor Details
-
LocaleState
public LocaleState(@NonNull Context applicationContext, @Nullable String sourceLocale, @Nullable String[] appLocales, @Nullable Locale currentLocale) Creates a LocaleState instance.- Parameters:
applicationContext- The application context.sourceLocale- The locale of the source language, defaults to "en" ifnullis provided.appLocales- A list of all locales supported by the application, including the source locale; defaults to[sourceLocale]ifnullis provided.currentLocale- Set tonullto use the system's locale, or set to a specific locale if your app uses its own locale.- See Also:
-
-
Method Details
-
getSourceLocale
The source locale.This is the locale that is used as the source when uploading the files to Transifex.
- See Also:
-
getAppLocales
The app's supported locales, including the source locale.- See Also:
-
getTranslatedLocales
The app's supported locales without the source locale.The array can be empty.
-
getCurrentLocale
The current locale as provided by Android or the the locale set usingsetCurrentLocale(Locale). -
getResolvedLocale
The resolved locale is one of the app locales that best matches the current locale.The matching follows Android's resource resolution strategy. At first, a locale that has the same language and region is searched for. If this fails, a locale that has the same language but no region defined is searched for. If this fails, a locale that has the same language but a different region is searched for. If this fails, the resolved locale is
null.- Returns:
- The resolved locale or
nullif no app locale matches the current locale.
-
setCurrentLocale
Set the locale used in the app.If set to
null, the SDK will automatically use the one selected at Android's settings when the app starts and will update to another locale if it's changed by the user while the app runs.If your app has its own implementation for selecting locale, you should call this method when initializing the SDK and when the locale changes.
Warning: if you set a custom locale, your app should also call the necessary Android methods for updating the locale there as well. If not, the SDK may not work correctly in plurals and some other cases.
- Parameters:
currentLocale- Set tonullto use the system's locale or to a specific locale, if your app uses its own locale.
-
isSourceLocale
public boolean isSourceLocale()Returnstrueif the source locale matchesthe resolved locale. If it's different or the resolved locale isnull, it returnsfalse.
-