1

I'm working on an Android application that requires support for multiple languages. I am considering using Firebase Remote Config to manage localization by storing the translations in JSON format, which would then dynamically update the app's strings.xml files at runtime. Is it possible to directly update strings.xml or a similar resource file at runtime using data fetched from Firebase? If so, how can this be implemented?

Additionally, I would appreciate any advice on whether this approach is advisable, or if there are better practices for handling dynamic localization in Android apps using Firebase.

What I Tried:

Data Class Setup: I created a data class in Kotlin to hold the localized strings after parsing them from the JSON retrieved from Firebase Remote Config. Programmatic Localization: Attempted to apply these parsed strings programmatically throughout the app instead of relying on the traditional strings.xml mechanism. Expectations vs. Reality:

Expected: I expected that once the JSON data was parsed into the data class, I could use these objects to dynamically update the UI with localized strings based on the user’s language settings. Actual Result: Despite the JSON being parsed correctly and the data class being populated with translation strings, I found no effective way to integrate these dynamic translations seamlessly across all parts of the app. The main issue is that without modifying the strings.xml at runtime (which is not possible), I cannot use Android's built-in resource system (R.string) to manage localization. Problems Faced:

The lack of integration with Android’s native resource system means I can't use familiar mechanisms like getString(R.string.some_string) to fetch and display the translated strings. This limits the scalability and maintainability of the solution, as it diverges from standard Android development practices.

1 Answer 1

2

For sure you won’t be able to modify the resource files at runtime because it is generated at compile time so the best approach for localization and support of multiple languages is to create string.xml files for each language.

res/values/strings.xml -> for the default resource and fallbacks
res/values-ar/strings.xml -> for the alternative resource like Arabic.

Also, you can manage your translation via the Android studio editor like:

  • First, open your strings.xml and you can find Open Editor option

enter image description here

  • Second, modify your translation

enter image description here

Edit: You can load them dynamically before the application starts and save them locally within Room as an example and use them anywhere in your application and update them if needed.

You can check the documentation for this approach here: https://developer.android.com/guide/topics/resources/localization#creating-alternatives

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the suggestions! I'm exploring how to leverage Firebase Remote Config for dynamic localization without pre-compiling strings. Any advice on implementing real-time updates directly in the app would be really helpful!
@SYEDMUHAMMADHARIS What about loading them before the app starts and saving them locally with Room for example and using them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.