From 72bfe74243d2ac986f4ae8ed8fd6b58c95aaad44 Mon Sep 17 00:00:00 2001 From: Herman Junge Date: Mon, 19 Mar 2018 13:51:51 -0300 Subject: [PATCH 1/2] Add script to verify locale strings --- app/scripts/verify-locale-strings.js | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 app/scripts/verify-locale-strings.js diff --git a/app/scripts/verify-locale-strings.js b/app/scripts/verify-locale-strings.js new file mode 100644 index 000000000..b1234a43c --- /dev/null +++ b/app/scripts/verify-locale-strings.js @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Locale verification script +// +// usage: +// +// node app/scripts/verify-locale-strings.js +// +// will check the given locale against the strings in english +// +//////////////////////////////////////////////////////////////////////////////// + +var fs = require('fs') +var path = require('path') + +console.log('Locale Verification') + +var locale = process.argv[2] +if (!locale || locale == '') { + console.log('Must enter a locale as argument. exitting') + process.exit(1) +} + +console.log("verifying for locale " + locale) + +localeFilePath = path.join(process.cwd(), 'app', '_locales', locale, 'messages.json') +try { + localeObj = JSON.parse(fs.readFileSync(localeFilePath, 'utf8')); +} catch (e) { + if(e.code == 'ENOENT') { + console.log('Locale file not found') + } else { + console.log('Error opening your locale file: ', e) + } + process.exit(1) +} + +englishFilePath = path.join(process.cwd(), 'app', '_locales', 'en', 'messages.json') +try { + englishObj = JSON.parse(fs.readFileSync(englishFilePath, 'utf8')); +} catch (e) { + if(e.code == 'ENOENT') { + console.log("English File not found") + } else { + console.log("Error opening english locale file: ", e) + } + process.exit(1) +} + +console.log('\tverifying whether all your locale strings are contained in the english one') + +var counter = 0 +var foundError = false +var notFound = []; +Object.keys(localeObj).forEach(function(key){ + if (!englishObj[key]) { + foundError = true + notFound.push(key) + } + counter++ +}) + +if (foundError) { + console.log('\nThe following string(s) is(are) not found in the english locale:') + notFound.forEach(function(key) { + console.log(key) + }) + process.exit(1) +} + +console.log('\tall ' + counter +' strings declared in your locale were found in the english one') + +console.log('\n\tverifying whether your locale contains all english strings') + +var counter = 0 +var foundError = false +var notFound = []; +Object.keys(englishObj).forEach(function(key){ + if (!localeObj[key]) { + foundError = true + notFound.push(key) + } + counter++ +}) + +if (foundError) { + console.log('\nThe following string(s) is(are) not found in the your locale:') + notFound.forEach(function(key) { + console.log(key) + }) + process.exit(1) +} + +console.log('\tall ' + counter +' english strings were found in your locale!') + +console.log('You are good to go') \ No newline at end of file From 03587c96d86b439ef924bde12cf0ce5012983f38 Mon Sep 17 00:00:00 2001 From: Herman Junge Date: Mon, 19 Mar 2018 14:16:11 -0300 Subject: [PATCH 2/2] Move file to development, fix JS --- .../verify-locale-strings.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) rename {app/scripts => development}/verify-locale-strings.js (83%) diff --git a/app/scripts/verify-locale-strings.js b/development/verify-locale-strings.js similarity index 83% rename from app/scripts/verify-locale-strings.js rename to development/verify-locale-strings.js index b1234a43c..b8fe5a7dc 100644 --- a/app/scripts/verify-locale-strings.js +++ b/development/verify-locale-strings.js @@ -50,47 +50,47 @@ try { console.log('\tverifying whether all your locale strings are contained in the english one') var counter = 0 -var foundError = false +var foundErrorA = false var notFound = []; Object.keys(localeObj).forEach(function(key){ if (!englishObj[key]) { - foundError = true + foundErrorA = true notFound.push(key) } counter++ }) -if (foundError) { +if (foundErrorA) { console.log('\nThe following string(s) is(are) not found in the english locale:') notFound.forEach(function(key) { console.log(key) }) - process.exit(1) +} else { + console.log('\tall ' + counter +' strings declared in your locale were found in the english one') } -console.log('\tall ' + counter +' strings declared in your locale were found in the english one') - console.log('\n\tverifying whether your locale contains all english strings') var counter = 0 -var foundError = false +var foundErrorB = false var notFound = []; Object.keys(englishObj).forEach(function(key){ if (!localeObj[key]) { - foundError = true + foundErrorB = true notFound.push(key) } counter++ }) -if (foundError) { +if (foundErrorB) { console.log('\nThe following string(s) is(are) not found in the your locale:') notFound.forEach(function(key) { console.log(key) }) - process.exit(1) +} else { + console.log('\tall ' + counter +' english strings were found in your locale!') } -console.log('\tall ' + counter +' english strings were found in your locale!') - -console.log('You are good to go') \ No newline at end of file +if (!foundErrorA && !foundErrorB) { + console.log('You are good to go') +} \ No newline at end of file