tapptic-spreadsheet-localize v1.2.1
Generate localization files for Android & iOS based on a Google Spreadsheet
Given a Google Spreadsheet, this script fetches keys & translations and generates localization files for both iOS & Android
Requirements
- Node.js v8.9.1 or above (https://nodejs.org/en/)
- npm v5.6.0 or above
Service account
In order to use this tool, you'll need a Service Account. All the instructions are available here: https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication?id=service-account
Installation
$ sudo npm install -g tapptic-spreadsheet-localizeUpdating
$ sudo npm update -g tapptic-spreadsheet-localizeSpreadsheet template
You should clone this template as you start a new iOS or Android project :
https://docs.google.com/spreadsheets/d/1kU8bMc6wbGUd8oO8PzzRyaKTFnI0OHapOusLhTmusz0/edit#gid=0
Make sure to publish (File -> Publish to the web) your spreadsheet before running the script.
Script template
localize.js
var Localize = require("tapptic-spreadsheet-localize");
var sheetId = "<YOUR SPREADSHEET KEY>";
var serviceAccountJsonPath = "<PATH TO JSON FILE>";
var sheets = '*'; // See "Advanced" below for more info
var transformer = Localize.fromGoogleSpreadsheet(require(serviceAccountJsonPath), sheetId, sheets);
transformer.setKeyCol('KEY');
transformer.save("values/strings.xml", { valueCol: "NL", format: "android" });
transformer.save("values-fr/strings.xml", { valueCol: "FR", format: "android" });
transformer.save("nl.lproj/Localizable.strings", { valueCol: "NL", format: "ios" });
transformer.save("fr.lproj/Localizable.strings", { valueCol: "FR", format: "ios" });Usage
- Save or copy the
localize.jsscript in your project's root folder - Set your spreadsheet's key, localizaton files paths, languages key, ...
- Run it with
node localize.js(assuming you are on the same working directory)

Advanced
You can decide to keep empty string in the generated files (to manage fallback per example)
transformer.save("fr.lproj/Localizable.strings", { valueCol: "FR", format: "ios", keepEmpty: true });You can filter the worksheets to include with the second parameter of fromGoogleSpreadsheet in your localize.js script :
var sheets = '*'; // Every sheet
var sheets = ['HomeScreen', 'ContactScreen']); // Sheet's name
var sheets = [0, 2]); // 1st & 3rd sheetIn Xcode you can add a Run Script Phase (Build Phases) to automatically execute the script everytime you compile. Make sure you add it above the Compile Sources phase.
if [[ \"${CONFIGURATION}\" = \"Debug\" ]]; then
export NODE_PATH=/usr/local/lib/node_modules/
node localize.js
fiNotes
The script will preserve everything that is above the tags: < !-- AUTO-GENERATED --> or // AUTO-GENERATED
FAQ
- When I run the script I get this error :
Error: Cannot find module 'tapptic-spreadsheet-localize'
Make sure your node path is set in your bash_profile. You can set it with the following commands:
$ echo "export NODE_PATH=/usr/local/lib/node_modules" >> ~/.bash_profile
$ source ~/.bash_profile