Localizing Android in-app strings without using Phrase
Intro
This is my first story on Medium. I am a Senior Android Developer and want to share some bits of my daily experience by writing short stories the way i’d like to read them by myself.
On the topic
These days my PO wants me to create a list of 374 built-in strings of an app to hand it over to a translation service which would translate all strings to 7 new languages. And of course after getting the translation results i would be the one with the task to apply the strings into the app. And no, Phrase or similar services was not an option.
How i resolved it
I choose Excel to have at least the opportunity to have everything in separate columns: The string identifiers next to the localized strings.
Copying the identifiers and the default language into the Excel sheet was easy:
- Open the strings.xml in the Translations Editor of Android Studio
- Select the columns of the identifiers and the default language and just copy and paste it to columns in the Excel sheet
My idea was to do it just the other way round when the translations would be ready.
- Of course i made sure not to change the order of the strings in strings.xml
As the translations arrived i realised that you can’t copy the localized strings as a whole list into the Translation Editor. Only string by string. Ok, agreed that this would blow up the scope of the editor. But what now?
Copying string by string? 374 strings for 7 languages? Oh No!
Looking for some tools that can do the job? Found some but none of them did really work out of the box. Fix them? Ok, when possible in one hour, but no!
Writing a tool by myself? Well, i just started to reactivate my bash and regex knowledge when my treasured colleague Ralph Bergmann gave me the solution:
- Given you have an Excel sheet now with two columns.
The first with the string identifiers and the second with the localized strings (for one language for now, but you can just hide the others). - In your Excel sheet add new columns left and right to the one with the string identifiers.
- In the left column add
<string name=”
at each row - In the right column add
“>
- In the column right to the localized strings add
</string>
- (Ok, now you already know how this will end up)
- Copy the whole block in your localized strings.xml and that’s it (almost, because in my case i needed to remove some tab characters here and there. Find & replace did the job