Keeping all your strings.xml
files synchronized in Android projects can be painful, as Eclipse doesn’t tell you which strings have no localized version in which language. Android is perfectly happy with it as well, it just uses the default (usually English) string in the app, much for the joy of your non-English users.
I came up with a simple Python script that just scans your res/values-**
folders for strings.xml
files and, using your default res/values/strings.xml
as reference, outputs a list of missing strings for each file, along with the original value set for the key.
So, if for instance your res/values/strings.xml
is this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My App</string>
<string name="title_activity_main">My Activity</string>
<string name="hello_world">Hello, World!</string>
</resources>
and your, say, res/values-it/strings.xml
is this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">La mia App</string>
<string name="title_activity_main">La mia Activity</string>
</resources>
and your… res/values-fr/strings.xml
? is this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Mon App</string>
<string name="hello_world">Bonjour, Monde!</string>
</resources>
the script would output:
Missing in /home/whatever/wherever/.../App/res/values-it/strings.xml:
<string name="hello_world">Hello, World!</string>
Missing in /home/whatever/wherever/.../App/res/values-fr/strings.xml:
<string name="title_activity_main">My Activity</string>
So the idea is that you can cut and paste those lines in the appropriate files to translate them.
The script also outputs some warnings in case it finds duplicate keys in any of the strings.xml
files.
Your localized strings.xml
files may have more <string>
items than the default, as no check is performed against that.
I put the script it in a folder within my Android projects that is simply ignored by Android (I usually call it not_in_apk
or something like that), so if you put it elsewhere remember to change the path at line 23
path_to_default = '../res/values/strings.xml'
to the path to your default strings.xml
file (absolute or relative, it should work anyway).
I didn’t do much testing, so it may not work for you… Worst thing that can happen is.. it doesn’t work 🙂
It won’t mess with your files, I promise you that.
Here’s the script! Run it with python i18n.py
.
Last note: this script only takes strings.xml
files into account, you should run Android Lint to check for strings to be translated in other XML files (stringarrays.xml
and other files).