Localization of Android applications using Google Sheets

Good afternoon!

In this article, I would like to share my little experience using Google Sheets when localizing an Android application. Initially, it was required to translate the developed application only into the customer’s language, i.e. Norwegian. At this time, the Translations Editor did not exist in IntelliJ Idea, and Android Studio was preparing to exit the beta.

The main requirement of the customer, not subject to discussion, was the fact that the translator should spend as little time as possible on the translation. So, the translator needs to provide a table with lines for the translation, he translates everything you need, and then do whatever you want with it. He could not install any additional software, not to mention SCM.

TL; DR finished document. To get the strings.xml files, click Export Files -> Export sheets to strings.xml. The Google Drive app, which must be installed on your machine, downloads the result.

At the very beginning, we used a simple Excel document for translation and email ping pong with a translator to communicate with him. After the manual transfer of ~ 100 rows from strings.xml to the table, the desire to continue this shameful lesson disappeared. Import from xml to the table was implemented using Excel tools . In the future, this document was surrounded by logic: various kinds of conditional formatting for visualizing newly added lines, support for the situation when the key to the line was renamed.

However, this whole structure had one big drawback - the lack of versioning. Our translator received a new file for the translation containing the already translated lines, as well as empty cells where this translation had to be entered. Everything was covered with a copper basin, when 2 more languages ​​were added: Swedish and Danish. Once, when merging 3 documents from 3 translators, I drove columns, because of this the wrong translations almost went into release.

As a result, a stick was received from the customer, as well as a new requirement: no complex logic in the table, only 4 columns - key, English source, Norwegian, Swedish and Danish translations. To avoid problems with multiple copies of the document from each of the translators, I persuaded the customer to use Google Sheets. I was no longer going to export translations to strings.xml in any manual way - I was more than satisfied with looking for discrepancies in the lines after the unfortunate merger of different copies of the translation, when sweat appeared on the forehead from staring into the monitor. Then it turned out that it’s very easy for Google services to write extensions in a JS-like language - Google Script.

Naturally, I was looking for ready-made services that solve this problem. The first 3 links in google and the answer to SOdid not give satisfactory results. By the way, by the time of moving to Google Sheets, a new version of Idea was released, where the Translations Editor appeared, this made life a little easier.

So, a table was created in Google documents with 5 columns - key, English, Norwegian, Swedish, Danish and comments, as well as access rights were distributed. To put data into a table from a project, you need to select everything in the Translation Editor and paste it into any table editor, delete the extra columns (Untranslatable - we don’t use it) and paste the result into the Google document. It is also necessary to mention that our project consists of several modules with their own translations, therefore there are 2 tabs in the document, and the described operations must be performed once for each project.

The result is a table with lines for the translation, which translators can easily edit together. When the translation is completed, you need to transfer the result back to your project. I began to think how I could get everything at once. The maximum effort that I was ready to go to is 1 copy. The only solution that occurred to me was to export the results to Google Drive, from where the desktop application will pull them on my PC. If the correct hierarchy of folders was previously created, then I can copy and overwrite strings.xml files in 1 action. Here without writing a small script can not do.

Click Tools-> Script Editor and get into an almost full-fledged IDE with auto-completion and debug directly in the browser! Also created a small piece of code that creates an additional menu you UI google tables. Clicking on this element will be the entry point.

function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Export Sheets To strings.xml",
    functionName : "readAndExport"
  spreadsheet.addMenu("Export Files", entries);

Next, simple code goes through the sheets (tabs), reads the column headers, compiles an xml string from the values ​​in the cells and writes it to the strings.xml file on your Google disk in the directory trunk / [sheet_name] / res / values- [column_name] / strings .xml. The source itself can be viewed directly in the file provided. Of the unusual, we can mention that in Google drive the name of the directory or file is not unique, i.e. You can create 2 files or directories with the same name. For everything to work correctly, you need to use something like this code:
function getOrCreate(root, name) {
  var iterator = root.getFoldersByName(name);
  if(iterator.hasNext()) {
    return iterator.next();
  } else {
    return root.createFolder(name);


Google Apps has a truly simple and powerful API. Another advantage is the fact that right out of the box there is access to the API of any Google application: calendar, disk, mail, etc. As soon as possible, I managed to create a simple and convenient tool for localizing our application. Of course, there are still places in it that I would like to improve, however, I got rid of the most important problem: copying and editing many files with the same structure and names. This inevitably led to errors caused by inattention.

Also popular now: