'android localized String resource with non-translatable word inside
Lets make string resource:
<string name="pin_code_title">Please enter PIN code</string>
or
<string name="enter_btc_tokens_amount">Enter amount of BTC tokens you want to send</string>
I use google translation service where I upload strings.xml to translate it automatically. And I want google to keep "PIN" and "BTC" [and some other brand names] untranslatable. And this is my problem. Google translates the whole string if it can.
I have checked android string resources docs
Solutions I see and still don't like:
To declare parameters:
<string name="pin_code_title">Please enter %s</string>or<string name="enter_btc_tokens_amount">Enter amount of %s you want to send</string>and then calltextView.text=...from Kotlin. -I don't like it because I use string resources in layouts.To use "Entities in XML" described here. I see comment "xml entities are not supported by translation services" comments and I hope that google translates xml files but keeps Entity untranslated.
What is the best practice to keep some words untranslated inside translatable string ?
Solution 1:[1]
I recommend LikeTheSalad gradle plugin.
We use it in production for a while without any issues.
An easy and intuitive way to use resource A as nested resource inside resource B.
I tweaked the example of the repo description for you purpose:
<resources>
<string name="pin" translatable="false">PIN</string>
<string name="pin_code_title">Please enter ${pin} code</string>
</resources>
This way, Google will translate Please enter ${pin} code (I believe they won't translate ${pin}), but in the final APK, the resource will be generated correctly: Please enter PIN code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shlomi Katriel |
