Reputation: 597
I've the following problem.
I know we can create a resource in the gradle file like this:
resValue "string", "app_id", "hello_world"
But is there any possibility to localize this string in different languages from within the gradle file?
Upvotes: 0
Views: 763
Reputation: 597
Finally I managed to do this just by creating different variables in gradle.properties and reference them in the strings.xml
Example:
Gradle.properties:
APP_NAME="HelloWorld"
APP_NAME_ES="HolaMundo"
build.gradle
resValue 'string', 'APP_NAME', APP_NAME
resValue 'string', 'APP_NAME_ES', APP_NAME_ES
strings.xml (english)
<string name="app_name">@string/APP_NAME</string>
strings_es.xml (english)
<string name="app_name">@string/APP_NAME_ES</string>
Upvotes: 1
Reputation: 14513
The Gradle Android plugin does not support the addition of localized resources. You can check the plugin documentation and its reference on the ProductFlavor
class for more details and an overview of all methods.
However, you could edit your question to explain the scenario that would require such a feature. The resValue
method is mainly used to add simple resources depending on the build, e.g. inserting the build number into the About section of the app.
Upvotes: 1
Reputation: 3861
This is not supported by default. Try to add your strings in localized folders or use flavors/dimensions.
Upvotes: 1