1.0.26 • Published 2 years ago

ios_translator v1.0.26

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

demonstration1.png

demonstration2.png

Install

    npm install ios_translator

Description

  • Translation is executed upon Google Cloud.
  • Translation quality wholly depends on Google Translate API
  • Generate localizable.strings

Features

  • translate

    • translate single word or phrase or sentence
  • listAvailableLanguages

    • fetch all available language lists for translation
    • returns json objects list for customization
  • generateLocalizableStrings

    • generate localizable.strings for various languages
    • returns json objects list for cutomization

Prepare

  • localizable.strings must be provided as input

demo.png

Usage

const fs = require("fs");
const iosTranslator = require("ios_translator");

const jsonData = fs.readFileSync(
  "./your_google_service_account_credential.json"
);
const credential = JSON.parse(jsonData);

iosTranslator.configure({
  googleApiCredential: credential,
  googleApiProjectId: credential.project_id,
  log: false,
});

const options = {
  input: "./path/to/localizable.strings",
  output: "./path/to/yourdirectory",
  from: "en",
  to: ["de", "fr"],
};

async function main() {
  const translatedJSON = await iosTranslator.generateLocalizableStrings(
    options
  );
}

main();

Configure

  1. Create your google account
  2. Enable Google Translate API
  3. Create Service Account
  4. Get json credential
const fs = require("fs");
const iosTranslator = require("ios_translator");

const jsonData = fs.readFileSync(
  "./your_google_service_account_credential.json"
);
const credential = JSON.parse(jsonData);

iosTranslator.configure({
  googleApiCredential: credential,
  googleApiProjectId: credential.project_id,
  log: false,
});

generateLocalizableStrings

  • Options

    • input => where your original file is

    • output => where your output files will be

    • from => indicate your original language

      example) "hello world" is english

    • to => provide your target languages

      example) if you provide these languages, "de", "fr", your localizable.strings will be translated into german and french

const fs = require("fs");
const iosTranslator = require("ios_translator");

const jsonData = fs.readFileSync(
  "./your_google_service_account_credential.json"
);
const credential = JSON.parse(jsonData);

iosTranslator.configure({
  googleApiCredential: credential,
  googleApiProjectId: credential.project_id,
  log: false,
});

const options = {
  input: "./path/to/localizable.strings",
  output: "./path/to/yourdirectory",
  from: "en",
  to: ["de", "fr"],
};
const translatedJSON = await iosTranslator.generateLocalizableStrings(options);

Code Example - all features

// Configure
const fs = require("fs");
const iosTranslator = require("ios_translator");

const jsonData = fs.readFileSync(
  "./your_google_service_account_credential.json"
);
const credential = JSON.parse(jsonData);

iosTranslator.configure({
  googleApiCredential: credential,
  googleApiProjectId: credential.project_id,
  log: false,
});

// returns 'bonjour'
const result = await iosTranslator.translate("hello", { from: "en", to: "fr" });

// returns objects (available languages for translation), [{ code: 'tk', name: 'Turkmen' }, { code: 'uk', name: 'Ukrainian' },]
const result = await iosTranslator.listAvailableLanguages();

// returns objects and generate `localizable.strings`
// Object will look like this
/*
    {
        "ko": {
            "key": "hello",
            "value": "안녕하세요"
        }
    }
*/
const options = {
  input: "./path/to/localizable.strings",
  output: "./path/to/yourdirectory",
  from: "en",
  to: ["de", "fr"],
};
const translatedJSON = await iosTranslator.generateLocalizableStrings(options);
1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago