-
- All Implemented Interfaces:
@Singleton() public final class LanguagesHelperClass used to handle language support related business logic.
-
-
Field Summary
Fields Modifier and Type Field Description private StringselectedLanguageCodeprivate final LocaleselectedLocaleprivate final StringselectedLanguage
-
Constructor Summary
Constructors Constructor Description LanguagesHelper(ConfigurationRepository configurationRepository, ResourcesHelper resourcesHelper, DidomiInitializeParameters initializeParameters)
-
Method Summary
Modifier and Type Method Description final StringgetSelectedLanguageCode()Selected language code, as handled by SDK config. final UnitsetSelectedLanguageCode(String selectedLanguageCode)Selected language code, as handled by SDK config. final LocalegetSelectedLocale()Selected Locale final StringgetSelectedLanguage()final Set<String>addCountryCodeIfNeeded(Set<String> languages)Add country code to language codes if needed. final StringaddCountryCodeIfNeeded(String language)Add country code to language code if needed. final StringgetCustomTranslation(Map<String, String> customContent, StringTransformation transform)Get translated content from a Map of custom content final StringgetCustomTranslation(Map<String, String> customContent)Get translated content from a Map of custom content final StringgetCustomTranslationWithDefault(Map<String, String> customContent, String key, StringTransformation transform)Get translated content either from a Map of custom content or from the default translations final StringgetCustomTranslationWithDefault(Map<String, String> customContent, String key)Get translated content either from a Map of custom content or from the default translations final BooleanselectedLanguageContainsDefaultCountry()Check if selectedLanguage contains default country. final Map<String, String>getText(String key)Method used to get a dictionary/map in the form of { "en": "Key in English", "fr": "Key in French." } for a given key. final StringgetTranslatedText(String key, StringTransformation transform, Map<String, String> additionalMacros)Method used to get a translated text based on the selected language and a given key. final StringgetTranslatedText(String key, StringTransformation transform)Method used to get a translated text based on the selected language and a given key. final StringgetTranslatedText(String key)Method used to get a translated text based on the selected language and a given key. final StringgetTranslation(String key, StringTransformation transform, Map<String, String> additionalMacros, String language)Get a translated text based on the selected language and a given key. final StringgetTranslation(String key, StringTransformation transform, Map<String, String> additionalMacros)Get a translated text based on the selected language and a given key. final StringgetTranslation(String key, StringTransformation transform)Get a translated text based on the selected language and a given key. final StringgetTranslation(String key)Get a translated text based on the selected language and a given key. final LanguageUpdateStatusupdateSelectedLanguage(String languageCode)Method used to change SDK language when user changes language within client app (if client app supports that feature) final UnitresetLanguage()Method used to change SDK language when device language changes -
-
Constructor Detail
-
LanguagesHelper
LanguagesHelper(ConfigurationRepository configurationRepository, ResourcesHelper resourcesHelper, DidomiInitializeParameters initializeParameters)
-
-
Method Detail
-
getSelectedLanguageCode
final String getSelectedLanguageCode()
Selected language code, as handled by SDK config. May differ with generated locale, see fallbackCodes in SDK master config.
-
setSelectedLanguageCode
final Unit setSelectedLanguageCode(String selectedLanguageCode)
Selected language code, as handled by SDK config. May differ with generated locale, see fallbackCodes in SDK master config.
-
getSelectedLocale
final Locale getSelectedLocale()
Selected Locale
-
getSelectedLanguage
final String getSelectedLanguage()
-
addCountryCodeIfNeeded
final Set<String> addCountryCodeIfNeeded(Set<String> languages)
Add country code to language codes if needed.
-
addCountryCodeIfNeeded
final String addCountryCodeIfNeeded(String language)
Add country code to language code if needed.
-
getCustomTranslation
@JvmOverloads() final String getCustomTranslation(Map<String, String> customContent, StringTransformation transform)
Get translated content from a Map of custom content
- Parameters:
transform- the string transformation to apply.
-
getCustomTranslation
@JvmOverloads() final String getCustomTranslation(Map<String, String> customContent)
Get translated content from a Map of custom content
-
getCustomTranslationWithDefault
@JvmOverloads() final String getCustomTranslationWithDefault(Map<String, String> customContent, String key, StringTransformation transform)
Get translated content either from a Map of custom content or from the default translations
- Parameters:
transform- the string transformation to apply.
-
getCustomTranslationWithDefault
@JvmOverloads() final String getCustomTranslationWithDefault(Map<String, String> customContent, String key)
Get translated content either from a Map of custom content or from the default translations
-
selectedLanguageContainsDefaultCountry
final Boolean selectedLanguageContainsDefaultCountry()
Check if selectedLanguage contains default country.
-
getText
final Map<String, String> getText(String key)
Method used to get a dictionary/map in the form of { "en": "Key in English", "fr": "Key in French." } for a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.
-
getTranslatedText
@JvmOverloads() final String getTranslatedText(String key, StringTransformation transform, Map<String, String> additionalMacros)
Method used to get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.transform- the string transformation to apply.additionalMacros- specific macros to use when formatting the text.
-
getTranslatedText
@JvmOverloads() final String getTranslatedText(String key, StringTransformation transform)
Method used to get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.transform- the string transformation to apply.
-
getTranslatedText
@JvmOverloads() final String getTranslatedText(String key)
Method used to get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.
-
getTranslation
@JvmOverloads() final String getTranslation(String key, StringTransformation transform, Map<String, String> additionalMacros, String language)
Get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.transform- the string transformation to apply.additionalMacros- specific macros to use when formatting the text.language- code of the language for which we want a translation For example, to format "Vendor %{name}" into "Vendor Didomi", pass a map containing "{name}" => "Didomi".
-
getTranslation
@JvmOverloads() final String getTranslation(String key, StringTransformation transform, Map<String, String> additionalMacros)
Get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.transform- the string transformation to apply.additionalMacros- specific macros to use when formatting the text.
-
getTranslation
@JvmOverloads() final String getTranslation(String key, StringTransformation transform)
Get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.transform- the string transformation to apply.
-
getTranslation
@JvmOverloads() final String getTranslation(String key)
Get a translated text based on the selected language and a given key.
- Parameters:
key- used to find its corresponding value in the dictionary/map.
-
updateSelectedLanguage
final LanguageUpdateStatus updateSelectedLanguage(String languageCode)
Method used to change SDK language when user changes language within client app (if client app supports that feature)
- Parameters:
languageCode-international short code (Coded2) for selected language.
-
resetLanguage
final Unit resetLanguage()
Method used to change SDK language when device language changes
-
-
-
-