diff --git a/packages/mobile/fastlane/Fastfile b/packages/mobile/fastlane/Fastfile index 3a9b4962c92..5c97c255b1c 100644 --- a/packages/mobile/fastlane/Fastfile +++ b/packages/mobile/fastlane/Fastfile @@ -14,7 +14,7 @@ def get_bundle(env) return $bundle_name + env end -def fastlane_supply(env, track, bundle_suffix, skip_deploy) +def fastlane_supply(env, track, bundle_suffix) return supply( json_key: 'fastlane/google-play-service-account.json', track: track, diff --git a/packages/mobile/scripts/translateFile.js b/packages/mobile/scripts/translateFile.js new file mode 100644 index 00000000000..e6b01e940d4 --- /dev/null +++ b/packages/mobile/scripts/translateFile.js @@ -0,0 +1,62 @@ +// Translate a file using google translate +// tslint:disable: no-console + +const fs = require('fs') +const request = require('request') + +const fileName = process.argv[2] +const googleApiToken = process.argv[3] +console.info(`Translating file: ${fileName}`) + +const json = fs.readFileSync(`../locales/en-US/${fileName}`) +const strings = JSON.parse(json) +console.info(`Found ${Object.keys(strings).length} strings`) + +function translateString(s) { + return new Promise((resolve, reject) => { + console.info(`Looking up ${s}`) + request.post( + 'https://translation.googleapis.com/language/translate/v2', + { + headers: { + Authorization: `Bearer ${googleApiToken}`, + }, + json: { + format: 'text', + q: s, + source: 'en', + target: 'es', + }, + }, + (error, res, body) => { + if (error) { + reject(error) + return + } + resolve(body.data.translations[0].translatedText) + } + ) + }) +} + +async function translateStrings(stringsToTranslate) { + const translations = {} + + const promises = Promise.all( + Object.keys(stringsToTranslate).map(async (key) => { + const val = stringsToTranslate[key] + + if (typeof val === 'string') { + const t = await translateString(val) + translations[key] = t + } else if (typeof stringsToTranslate === 'object') { + translations[key] = await translateStrings(val) + } + }) + ) + + await promises + return translations +} + +translateStrings(strings).then((translations) => console.log(JSON.stringify(translations)))