tapptic-spreadsheet-localize

1.2.1 • Public • Published

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

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-localize

Updating

$ sudo npm update -g tapptic-spreadsheet-localize

Spreadsheet 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

  1. Save or copy the localize.js script in your project's root folder
  2. Set your spreadsheet's key, localizaton files paths, languages key, ...
  3. Run it with node localize.js (assuming you are on the same working directory)

enter image description here

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 sheet

In 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
fi

Notes

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

Readme

Keywords

none

Package Sidebar

Install

npm i tapptic-spreadsheet-localize

Weekly Downloads

0

Version

1.2.1

License

none

Unpacked Size

33.8 kB

Total Files

8

Last publish

Collaborators

  • lucasadam
  • fde