Best practice for key values in translation files

This is a question that is also faced by iOS/OSX developers. And for them there is even a standard tool called genstrings which assumes method 1. But of course Apple developers don’t have to use this tool–I don’t.

While the safety net that you get with method 1 is nice (i.e you can display the key if you somehow forgot to localize a string) it has the downside that it can lead to conflicting keys. Sometimes one identical piece of display text needs to be localized in two different ways, due to grammar rules or differences in context. For instance the French translation for “E-mail” would be “E-mail” if it’s a dialog title and “Envoyer un e-mail” if it’s a button (in French the word “E-mail” is only a noun and can’t be used as a verb, unlike in English where it’s both a noun and a verb). With method 2 you could have keys EMAIL_TITLE and EMAIL_BUTTON to solve this issue, and as a bonus this would give a hint to translators to help them translate correctly.

One more advantage of method 2 is that you can change the English text without having to worry about updating the key in English and in all your localizations.

So I recommend method 2!

Leave a Comment