Home > other >  Remotely manageable multi language support on android
Remotely manageable multi language support on android

Time:03-03

I want to be able to modify a language file without publishing a new release of apk.

I've used paid tools for this localization issues before. I 'm trying to handle it without a product or tools.

Can I do this myself? I want to use a json language file that I received from the service as a key value in my android application.

For example, after selecting the language on the login page, I think I can download this language json file to my locale and use it as a language file.

How reliable is it? how performance is?

There is a firebase remote config, but I guess it is not used much for this purpose. Please write your suggestions..

CodePudding user response:

Firebase remote confis is actually a perfect use case for this a/b testing of your features.

There are alternatives as well but none with more documentation than remote config.

The logic how i have seen done is having a multimodule project and all resources accessed from a vernacular module . The remote config to switch between the languages.

I believe this can be achieved by 2 localized string files as well and use remote config to switch between them .

CodePudding user response:

You can download the languages as json and save it locale in HashMap where is the key is the same keys in your stings file .. and create extension function called getCustomString(stringName: String) at this method you first check the hashMap if there is a value which is downloaded and parsed from json you return it .. if not you can get the default value in strings file with the following code

fun AppCompatActivity.getCustomString(stringName: String): String {
return if (yourMap.containsKey(stringName)) {
    yourMap[stringName]
} else {
    val resId = resources.getIdentifier(aString, "string", packageName)
    getString(resId)
}
}
  • Related