Translate Strings XML - Python Code and Web Tool

As many of us know, translating strings into many different languages can be extremely tedious when done manually. Determined to find a better way, I googled "easy way to translate strings in xml" and stumbled on this glorious free Python code available in GitHub with a corresponding web tool if you don't feel like setting up your own Python program. It uses Google Translate, and the web tool prints to an html so you can watch it as it goes. Then you can download the translated file.

Link to source code on GitHub: https://github.com/Ra-Na/GTranslate-strings-xml 

Link to web tool: https://asrt.gluege.boerde.de

The author has a donate button on the web tool page, and I know many of us can relate to coding stuff for free and wanting some thanks. So show this person some love if you find this useful. It was a game changer for me, and I'm glad I didn't have to start from scratch to make my own code for this.

----------

UPDATE March 24, 2024:

Google has since started cracking down on automated pings to Google Translate, such that you have to subscribe to an account if you want to run a script that translates a lot of strings at a time instead of one-by-one. The above web tool no longer works, I assume for this reason. When I tried downloading the GitHub Python source code and running it on my local machine (after making some edits), it worked for a while, but then I started getting error messages from Google saying that they detected automated pings. Note that the GitHub also includes scripts for other translation platforms, but these also require subscriptions. When I started looking into the subscription for Google, it involved some setup in Google Cloud (i.e., not a simple sign up). It might be worth it if you have lots and lots of strings and translations for several apps, but it wasn't worth it for me.

A feasible alternative is the VS Code extension Google Translate by benshabatnoam. With it, you can highlight a string and translate it with a simple keyboard shortcut in VS Code. You can specify the 'translate to' language in the VS Code User Settings for the extension. I assume the 'translate from' language is automatically detected.

I found it convenient to have the settings.json file open in its own tab alongside all of my different strings.xml files in their own tabs, so when I wanted to change the translation language, I just typed it in the json file. You can also have a list of languages to choose from, but every time you press the keyboard shortcut, you have to choose which language you want. I found it easier to set one language, translate all strings in the corresponding xml, then switch to the next language for the next xml, etc.

I also found that this extension is useful for translating app descriptions for the CIQ website, e.g., in a txt file. I'm using separate files for Description and What's New so I can select all when I copy and paste it online.

DISCLAIMER: As with any automated translation, Google Translate is not perfect, and it may need some proofreading. Even if you're not fluent in a language, you can probably spot inconsistencies (such as "Soleil" instead of "Dim" for the abbreviation "Sun" for "Sunday"), so make sure to do a quick check for each string as you go.

Note that the extension uses Google's language codes which are different from Garmin's. The developer provides a list of language codes in the info page, but I like having a cheat sheet comparison to Garmin's codes so I can quickly choose the appropriate xml based on the resources directory name. For starters, here's my cheat sheet:

CIQ     Google Language
ces     cs     Czech
chs     zh-CN  Chinese (Simplified)
cht     zh-TW  Chinese (Traditional)
dan     da     Danish
deu     de     German
dut     nl     Dutch
est     et     Estonian
fin     fi     Finnish
fre     fr     French
gre     el     Greek
heb     iw     Hebrew
hrv     hr     Croatian
hun     hu     Hungarian
ind     id     Indonesian
ita     it     Italian
jpn     ja     Japanese
nob     no     Norwegian
pol     pl     Polish
por     pt-BR  Portuguese (Brazil)
por     pt-PT  Portuguese (Portugal)
ron     ro     Romanian
rus     ru     Russian
slo     sk     Slovak
slv     sl     Slovenian
spa     es     Spanish
swe     sv     Swedish
tha     th     Thai
tur     tr     Turkish
vie     vi     Vietnamese
zsm     ms     Malay


Google Language                 CIQ Website
cs     Czech                    Čeština
da     Danish                   Dansk
de     German                   Deutsch
el     Greek                    Ελληνικά
es     Spanish                  Español
fi     Finnish                  Suomi
fr     French                   Français
hr     Croatian                 Hrvatski
hu     Hungarian                Magyar
id     Indonesian               Bahasa Indonesia
it     Italian                  Italiano
iw     Hebrew                   עִברִית
ja     Japanese	                日本語
ko     Korean                   한국어
ms     Malay                    Bahasa Melayu
nl     Dutch                    Nederlands
no     Norwegian                Norsk
pl     Polish                   Polski
pt-BR  Portuguese (Brazil)      Português (Brasil)
pt-PT  Portuguese (Portugal)    Português (Portugal)
ru     Russian                  Русский
sk     Slovak                   Slovenčina
sl     Slovenian                Slovenščina
sv     Swedish                  Svenska
th     Thai                     ไทย
zh-CN  Chinese (Simplified)     简体中文
zh-TW  Chinese (Traditional)    繁體中文

  • Note: This tool was developed for Android apps, so the 3-letter language code may need to be tweaked since they use a different ISO (e.g., French is "fra" instead of "fre"). And just like any translation algorithm, you may need to tweak some of the translations themselves (e.g., abbreviated day of the week "Sun" translates literally to "Soleil" in French). But I can live with those things. If you really want a fully automated solution, you can add your own exceptions in the Python source code.

  • UPDATE: The web tool no longer works, and I am now using an extension in VS Code. See updated post above.

  • Can you share your experience with automated translations? I would think that it's not perfect and when I see this type of "nonsense" translations in a language I understand I'd rather have it in English (though this doesn't help with all the Chinese gadgets I guess). Do you have any feedback from users? Did you try to auto-translate to a language you understand? How good it is?

  • Since starting to use automated translations a couple of years ago, I think I've had only one user give feedback on a correction that needed to be made to the day of the week abbreviation displayed on the watch face, and one other time there was a typo in the specific character used. For month and weekday abbreviations, I carefully translate those manually, comparing to sources on the internet that specifically explain it. I am not fluent in any language besides English, but I know bits and pieces of French and German. Just like with computer programming languages, spoken languages with similar origins (e.g., Latin-based) have several commonalities in syntax etc. So as I'm pasting translations for strings, I can notice when one looks a bit odd compared to other similar strings, even if it's in a language I've never been exposed to much before. After a while, it starts to become educational. :)

    For abbreviations and small phrases within the app and settings, I think there is a little more leeway in the translation because it's not complete sentences, and the main purpose is to understand functionality.

    For the app description on the website, I just translate it all without proofreading it. It's probably not that great, but my biggest motivation for doing so was that one of my apps has unique features that people need to know about (the time of day can be intentionally changed for different circadian rhythms). If the user doesn't need those features, I want them to use the other app instead.

    The translations are not perfect, but if I were a user who did not speak English, I would appreciate a less-than-perfect translation over no translation.

  • Do you also translate to all the non Latin alphabet languages, like Chinese, Korean, Japanese, and the RTL languages, like Arabic, Hebrew?

  • Right now I’m translating to some of those languages for the CIQ website only, and I eventually want to use them on the app. The main differences are that I am using a custom bmp font for the app and would need to make new font files, and I would need to do more research to make sure I got the abbreviations correct for months and weekdays. I might reach out to a friend who is fluent to give feedback before publishing. In other forum posts, I’ve seen other people translating to those languages.

  • For the CIQ website, I was previously translating via Microsoft Word, which properly displays RTL text as RTL. When I pasted it on the website, though, I noticed it was LTR. Seems like a limitation of the website.