Convert a Google Spreadsheet to a localization file
Installation
npm install localize-spreadsheet-bot
Features Support
- Native iOS file format output
- Native Android string xml file output see example
- react-native-i18n JS file output based on react-native-i18n
- json JS file output
- dart JS file output
- dartTemplate schema file output
- .net schema file output
- generate type flow from Utility Types
- Laravel framework PHP supports See example
Example to develop your pipeline
Given a Google Spreadsheet like this:
The tool fetch the spreadsheet and write the result to a file in the Android or iOS format:
Create a file update-localization.js
var Localize = require("localize-with-spreadsheet");
var transformer = Localize.fromGoogleSpreadsheet("0Aq6WlQdq71FydDZlaWdmMEUtc2tUb1k2cHRBS2hzd2c", '*');
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" });
transformer.save(".../to/path/fr.json", {valueCol:"FR", format:"react-native-i18n"});
transformer.save(".../to/path/zh.json", {valueCol:"ZH", format:"react-native-i18n"});
transformer.saveFlowTypeFileJs(".../to/path/types.js");
Run it with
node update-localization.js
Advanced
You can filter the worksheets to include with the second parameter of 'fromGoogleSpreadsheet' Ex:
Localize.fromGoogleSpreadsheet("<Key>", '*');
Localize.fromGoogleSpreadsheet("<Key>", ['HomeScreen, 'ContactScreen']);
Localize.fromGoogleSpreadsheet("<Key>", [0, 2]);
Notes
- The script will preserve everything that is above the tags: < !-- AUTO-GENERATED --> or // AUTO-GENERATED
- Your spreadsheet should be "Published" for this to work
- You need to have git installed for the installation
From Android Res Folder
If you got the existing resources developed under Android Resource folder, you can use one of these library to generate Google Sheet format based on the original translation file. Install the module into your IDE and it will do that magic Source