I have an app translated in 3 languages: English, German, Polish
So I have these three folders for the languages in the project:
values
strings.xml
values-en
strings.xml
values-de
strings.xml
values-pl
strings.xml
I have realized that If I put all strings into values folder and have some strings missing in the Polish version that the app crashes when accessing the missing strings in the Polish version.
I would have expected that the system just gets the string from the default values folder if it does not find it in values-pl folder.
Is there any way to catch these potential missing string crashes? EVen if I could get a warning in the compiler that the string in any language is missing would be OK?
EDIT AND ADDITION
In fact another string was missing in the default too.... so thanks for the answer/comments!
But now I have also tested the case where there is a string simply missing in the default strings.xml file only BUT present in all the other files. I do not get any warning or anything else.
So in this case if ALL the strings are present in de,en,pl but one is missing in default, then the app crashes in China for example (I understand of course because the default is missing).
BUT what bothers me is that I do not find any way to check the completeness of all referenced strings in code. This is how I access the missing string:
context.getString(R.string.MYTRING_abc),
In eclipse menu Window --> Properties --> Android --> Lint Error Checking
in the Correctness:Messages
section set MissingTranslation
to Error in the Severity
box. When compile in your default values string.xml each untranslated string would be marked.
Most of the time after build you have to click the refresh icon
in the Link Warnings
window (next to Outline window
) to have these errors shown.
If there is error after fixing them you have to clean your project, otherwise Eclipse won't built and still show these errors.
I would have expected that the system just gets the string from the default values folder if it does not find it in values-pl folder.
It works that way for <string>
s, but not for the elements of <string-array>
s. If one of the translations has a <string-array>
without the correct number of elements, you'll get a crash if the app attempts to access a missing element. My solution for the past couple years has been to store every string array in a non-translated XML file, referencing translatable strings.
res/values/misc.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- Resources that are neither styles nor strings to be translated. -->
<resources>
<string-array name="notification_line_content_entries">
<item>@string/time_remaining</item>
<item>@string/time_since_status_change</item>
<item>@string/vital_signs</item>
</string-array>
</resources>
This way if one of the independent strings isn't translated, the array is still valid and you fall back to the default translation for that particular value.
Of course the other possibility is that, as suggested in the comments, you don't have a default translations for every string in res/values/
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With