Reputation: 508
I'm providing Arabic support for the already-completed app. On changing the app language to Arabic, numbers are displaying with Arabic digits for the XML strings.
But my problem is on executing the following code
getString(R.string.value, ++value);
values
<string name="value">Value : %d</string>
values-ar
<string name="value">%d :القيمة </string>
with English, it is working fine.
Value: 1
On changing the language to Arabic (Appearing in Arabic). It must be in English (0-9)
Value : (Number in Arabic)
Please provide a solution to my problem.
Upvotes: 4
Views: 2776
Reputation: 41
Although it takes a long time to ask this question (7 months), it may be useful for others. I did this 👇 and my problem was solved.
First I created a Locale variable:
val englishLocale = Locale("en")
Then I used this variable in the required functions:
For example for date format:
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", englishLocale)
Or to display elapsed time in milliseconds in normal format:
String.format(englishLocale, "%02d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, seconds % 60)
Upvotes: 0
Reputation: 22832
You can change the locale of the number using String.format
to always be shown in English:
String.format(Locale.ENGLISH, getString(R.string.value), ++value)
Upvotes: 6