Giter Site home page Giter Site logo

eran247 / localize-with-spreadsheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jambl/localize-with-spreadsheet-2

0.0 0.0 0.0 1.97 MB

Create a localization file in Android or iOS format from a Google Spreadsheet. Version 2

JavaScript 100.00%

localize-with-spreadsheet's Introduction

Convert a Google Spreadsheet to a localization file. Version 3

Installation

npm install ebs-integrator/localize-with-spreadsheet

Differences in version 3.0.0

  • Uses newer version of google-spreadsheet which in turn supports the Google Sheets v4 API

Example

Requires:

Setup

  1. Create a file update-localization.js
var Localize = require("localize-with-spreadsheet");

const credentials = {
  type: "service_account",
  project_id: "",
  private_key_id: "",
  private_key: "",
  client_email: "",
  client_id: "",
  auth_uri: "",
  token_uri: "",
  auth_provider_x509_cert_url: "",
  client_x509_cert_url: "",
};

const spreadsheet_key = "";
Localize.fromGoogleSpreadsheet(credentials, spreadsheet_key, "*").then(
  (localizer) => {
    localizer.setKeyCol("KEY");
    localizer.setDefaultLanguage('en')

    localizer.save("resource/Localizable.strings", {
      valueCol: "en",
      format: "ios",
    });
    localizer.save("resource/strings.xml", {
      valueCol: "en",
      format: "android",
    });
  }
);
  1. Create a Service Account and fill the credentials above: https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication?id=service-account

  2. Share your google sheet with the email in client_email field.

  3. Get the spreadsheet key from the document url: https://docs.google.com/spreadsheets/d/{spreadsheet_key}/

  4. Run it with node update-localization.js

An alternative for Localizer script

/* ... */

Localize.fromGoogleSpreadsheet(credentials, spreadsheet_key, '*').then(localizer => {
    localizer.setKeyCol('KEY')
    localizer.setDefaultLanguage('en')

    Array.from(['en', 'fr']).forEach(language => localizer.save(
        localizer.save("Localizable.strings", { valueCol: "en", format: "ios" });
        `resource/${language}/Localizable.strings`,
        { valueCol: language, format: 'ios' } // format can also be 'android' or 'json'
    ))
})

Advanced

You can filter the worksheets to include with the third parameter of 'fromGoogleSpreadsheet':

Localize.fromGoogleSpreadsheet('[service-account]', '[spreadsheet-key]', '*')
Localize.fromGoogleSpreadsheet('[service-account]', '[spreadsheet-key]', '[Sheet1]')
Localize.fromGoogleSpreadsheet('[service-account]', '[spreadsheet-key]', 0)

Configure XCode to automatically download localization on build

  1. Add update-localization.js in root folder of the project
  2. Create a New Run Script Phase and add this code:
if which node >/dev/null; then
node update-localization.js
fi

Notes

  • The script will preserve everything that is above the tags: < !-- AUTO-GENERATED --> or // AUTO-GENERATED

Credits

  • Originally cloned from https://github.com/xvrh/localize-with-spreadsheet.

localize-with-spreadsheet's People

Contributors

neverwintermoon avatar xvrh avatar nrj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.