Google Spreadsheets to XML for Android multiple languages management

To support different languages in Android, we need to create multiple strings.xml files and separate to each language folders.

res/
values/
strings.xml # English
values-fr/
strings.xml # French
values-es/
strings.xml # Spain

A simple structure for an app support 3 different languages.

It’s should be ok if the content is just several lines. But it’s hard to control when we work within a cross-functional team involves editors, translators, who don’t know anything about this.

Solution

A convenient way is to manage content in a Google Spreadsheets‎.

  • Developers manage the key strings
  • Editors, Translators only take care of the content in language columns

When there is a change in Spreadsheets‎, we use a script to extract it to string.xml and replace the string.xml content in our project.

A sample sheet to manage multiple languages

Export Spreadsheets‎ to XML

There are many ways to extract the content from google spreadsheets. But for me, Python is the easiest way to go, since there is a drop-in library to deal with it.

How to use

  • You will need Python 2.7 and install pygsheets
  • Follow this instruction to get authorization credentials for use in calling Google APIs
  • Store the credentials in the same folder with exporter.py
  • Execute the below command from terminal
python exporter.py

On the first time, It will request permissions to manage Drive and Spreadsheets

Result

Finally, we will have 3 different files for each language en.xml, fr.xml, es.xml. Then we just need to replace the content to strings.xml in our project.