aboutsummaryrefslogtreecommitdiffstats
path: root/development/verify-locale-strings.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-03-28 11:09:15 +0800
committerkumavis <aaron@kumavis.me>2018-03-28 11:09:15 +0800
commit3e7d7205b8b841f619a77da6c2d28da88fef66a7 (patch)
treee4b9b16068be647505402b374a40e8b84fe58878 /development/verify-locale-strings.js
parent8421cf1954fb017dc5311368cc3ee335b34ca446 (diff)
downloadtangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar.gz
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar.bz2
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar.lz
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar.xz
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.tar.zst
tangerine-wallet-browser-3e7d7205b8b841f619a77da6c2d28da88fef66a7.zip
i18n - cleanup verify locales util
Diffstat (limited to 'development/verify-locale-strings.js')
-rw-r--r--development/verify-locale-strings.js146
1 files changed, 80 insertions, 66 deletions
diff --git a/development/verify-locale-strings.js b/development/verify-locale-strings.js
index b8fe5a7dc..c0214d672 100644
--- a/development/verify-locale-strings.js
+++ b/development/verify-locale-strings.js
@@ -10,87 +10,101 @@
//
////////////////////////////////////////////////////////////////////////////////
-var fs = require('fs')
-var path = require('path')
+const fs = require('fs')
+const path = require('path')
+const locales = require('../app/_locales/index.json')
console.log('Locale Verification')
-var locale = process.argv[2]
-if (!locale || locale == '') {
- console.log('Must enter a locale as argument. exitting')
- process.exit(1)
+const specifiedLocale = process.argv[2]
+if (specifiedLocale) {
+ console.log(`Verifying selected locale "${specifiedLocale}":\n\n`)
+ const locale = locales.find(locale => locale.code === specifiedLocale)
+ verifyLocale({ locale })
+} else {
+ console.log('Verifying all locales:\n\n')
+ locales.forEach(locale => {
+ verifyLocale({ locale })
+ console.log('\n')
+ })
}
-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)
+
+function verifyLocale({ locale }) {
+ const localeCode = locale.code
+ const localeName = locale.name
+ console.log(`Status of "${localeName}" (${localeCode})`)
+
+ try {
+ const localeFilePath = path.join(process.cwd(), 'app', '_locales', localeCode, 'messages.json')
+ 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 ("${localeCode}") file: `, e)
+ }
+ process.exit(1)
}
- 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)
+ try {
+ const englishFilePath = path.join(process.cwd(), 'app', '_locales', 'en', 'messages.json')
+ 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)
}
- process.exit(1)
-}
-console.log('\tverifying whether all your locale strings are contained in the english one')
+ // console.log(' verifying whether all your locale ("${localeCode}") strings are contained in the english one')
+
+ var counter = 0
+ var foundErrorA = false
+ var notFound = [];
+ Object.keys(localeObj).forEach(function(key){
+ if (!englishObj[key]) {
+ foundErrorA = true
+ notFound.push(key)
+ }
+ counter++
+ })
-var counter = 0
-var foundErrorA = false
-var notFound = [];
-Object.keys(localeObj).forEach(function(key){
- if (!englishObj[key]) {
- foundErrorA = true
- notFound.push(key)
+ if (foundErrorA) {
+ console.log('\nMissing from english locale:')
+ notFound.forEach(function(key) {
+ console.log(` - [ ] ${key}`)
+ })
+ } else {
+ // console.log(` all ${counter} strings declared in your locale ("${localeCode}") were found in the english one`)
}
- counter++
-})
-if (foundErrorA) {
- console.log('\nThe following string(s) is(are) not found in the english locale:')
- notFound.forEach(function(key) {
- console.log(key)
- })
-} else {
- console.log('\tall ' + counter +' strings declared in your locale were found in the english one')
-}
+ // console.log('\n verifying whether your locale ("${localeCode}") contains all english strings')
-console.log('\n\tverifying whether your locale contains all english strings')
+ var counter = 0
+ var foundErrorB = false
+ var notFound = [];
+ Object.keys(englishObj).forEach(function(key){
+ if (!localeObj[key]) {
+ foundErrorB = true
+ notFound.push(key)
+ }
+ counter++
+ })
-var counter = 0
-var foundErrorB = false
-var notFound = [];
-Object.keys(englishObj).forEach(function(key){
- if (!localeObj[key]) {
- foundErrorB = true
- notFound.push(key)
+ if (foundErrorB) {
+ console.log(`\nMissing from "${localeCode}":`)
+ notFound.forEach(function(key) {
+ console.log(` - [ ] ${key}`)
+ })
+ } else {
+ // console.log(` all ${counter} english strings were found in your locale ("${localeCode}")!`)
}
- counter++
-})
-if (foundErrorB) {
- console.log('\nThe following string(s) is(are) not found in the your locale:')
- notFound.forEach(function(key) {
- console.log(key)
- })
-} else {
- console.log('\tall ' + counter +' english strings were found in your locale!')
+ if (!foundErrorA && !foundErrorB) {
+ console.log('You are good to go')
+ }
}
-
-if (!foundErrorA && !foundErrorB) {
- console.log('You are good to go')
-} \ No newline at end of file