Recently, my team and I faced an issue when we had to ship a specific flavor of our application with only one locale and without a default locale. In other words, we had the task to somehow swap all the English texts we had in the default strings.xml with Spanish strings we had in values-es/strings.xml. While looking for a solution, we found several almost workable variants:
First what came to our minds is enabling the resConfigs "es" in the build.gradle file. As we had a special flavor for this kind of APK, we could possibly do it. But! If a user is not in the Spanish locale, then he will have the English one. We didn’t want it to happen, so it wasn’t really our choice.
Next, we found a possible solution by switching the locale in the runtime. It can be done like this:
This method worked almost everytime but not always. So again, we had to seek another solution.
We came up with a little ‘brute-force’ method but one can be pretty sure of showing the right strings to the user. We wrote a groovy script that moves Spain strings to the default strings.xml and then deletes the values-es/strings.xml file. It looks like this:
This script can be easily included in the build.gradle file of the app, so feel free to do that!