ios_translator
v1.0.26
Published
iOS translator. Create localizable.strings
Downloads
11
Readme
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
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
- Create your google account
- Enable Google Translate API
- Create Service Account
- 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);