1. Setup Google Doc Sheet
Create a google doc sheet, it should have the following format:
In order for it to be accessible via the API, it should be public and published to the web. This can be achieved by selecting File -> Publish to the web...
2. Node.js
Make sure node.js is installed on your machine. Use the following command:
npm -v
If it's not installed, go to https://nodejs.org/en/download/ and do it.
3. Create main directory and install localization plugin
mkdir UpdateLocalization
cd UpdateLocalization
git clone https://github.com/xavierha/localize-with-spreadsheet.git
cd localize-with-spreadsheet
npm install
4. Create update localization script
cd ..
touch update-localization.js
Write to update-localization.js
. The example content:
var Localize = require("localize-with-spreadsheet");
var transformer = Localize.fromGoogleSpreadsheet("GOOGLE_DOC_ID", '*');
transformer.setKeyCol('KEY');
transformer.save("PROJECT_FOLDER/Resources/Base.lproj/Localizable.strings", { valueCol: "EN", format: "ios" });
transformer.save("PROJECT_FOLDER/Resources/ru.lproj/Localizable.strings", { valueCol: "RU", format: "ios" });
Replace GOOGLE_DOC_ID
with the actual google doc ID. it can be found in doc's URL:
docs.google.com/spreadsheets/d/ 1n0ITsW53GZDfYZ0wz4ZOU1wJBzZQG4mHtPTjmmQM6_U
/edit#gid=0
KEY
is the column to be used for keys.
Replace PROJECT_FOLDER
with your project's folder real name. Add appropriate languages and paths.
5. Add it to the project
Firstly, remove everything from the UpdateLocalization
, except of node_modules
, core
and update-localization.js
. Then add UpdateLocalization
folder to the project's root as a folder (not category), so it is added as a blue folder (not yellow). Also, don't associate it with any target, so these files don't get into final application:
6. Create a run script
Go to project configuration, select your target and select Build Phases
. Click +
button and select New Run Script Phase
. A new script should appear. Click on its title and rename to UpdateLocalization
. Expand it and paste:
node UpdateLocalization/update-localization.js
Now the script should be executed upon each build (including runs).