Class LanguagesHelper
-
- All Implemented Interfaces:
@Singleton() public final class LanguagesHelperHandle language support related business logic.
-
-
Field Summary
Fields Modifier and Type Field Description private final StringdefaultLanguageprivate 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 StringgetDefaultLanguage()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, applying default macros 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 StringgetCustomTranslationIgnoringMacros(Map<String, String> customContent, String key)Return translated text, without replacing macros final BooleanlanguageContainsDefaultCountry(String baseLanguageCode)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)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 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 final UnitupdateVendorsCount(Integer allVendors, Integer iabVendors, Integer nonIABVendors)Update macros with partners count info -
-
Constructor Detail
-
LanguagesHelper
LanguagesHelper(ConfigurationRepository configurationRepository, ResourcesHelper resourcesHelper, DidomiInitializeParameters initializeParameters)
-
-
Method Detail
-
getDefaultLanguage
final String getDefaultLanguage()
-
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
final String getCustomTranslation(Map<String, String> customContent, StringTransformation transform)
Get translated content from a Map of custom content, applying default macros
- Parameters:
transform- the string transformation to apply.
-
getCustomTranslationWithDefault
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.
-
getCustomTranslationIgnoringMacros
final String getCustomTranslationIgnoringMacros(Map<String, String> customContent, String key)
Return translated text, without replacing macros
-
languageContainsDefaultCountry
final Boolean languageContainsDefaultCountry(String baseLanguageCode)
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
final String getTranslatedText(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
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".
-
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
-
updateVendorsCount
final Unit updateVendorsCount(Integer allVendors, Integer iabVendors, Integer nonIABVendors)
Update macros with partners count info
-
-
-
-