mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
93204a578b
* Add extra locales to index.json * Fix verify locale script bugs - All locales didn't work because it was putting an object inside of an object. - Individual checks didn't work because of how the destructuring was done. - Extra items were being printed as missing items. * Sync up string changes w/ Brave wallet * Add 33 new locales from Brave wallet * Merge tml into ta code
95 lines
3.1 KiB
JavaScript
95 lines
3.1 KiB
JavaScript
// //////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Locale verification script
|
|
//
|
|
// usage:
|
|
//
|
|
// node app/scripts/verify-locale-strings.js <locale>
|
|
//
|
|
// will check the given locale against the strings in english
|
|
//
|
|
// //////////////////////////////////////////////////////////////////////////////
|
|
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const localeIndex = require('../app/_locales/index.json')
|
|
|
|
console.log('Locale Verification')
|
|
|
|
const specifiedLocale = process.argv[2]
|
|
if (specifiedLocale) {
|
|
console.log(`Verifying selected locale "${specifiedLocale}":\n\n`)
|
|
const locale = localeIndex.find(localeMeta => localeMeta.code === specifiedLocale)
|
|
verifyLocale(locale)
|
|
} else {
|
|
console.log('Verifying all locales:\n\n')
|
|
localeIndex.forEach(localeMeta => {
|
|
verifyLocale(localeMeta)
|
|
console.log('\n')
|
|
})
|
|
}
|
|
|
|
|
|
function verifyLocale ({ code, name }) {
|
|
let targetLocale, englishLocale
|
|
try {
|
|
const localeFilePath = path.join(process.cwd(), 'app', '_locales', code, 'messages.json')
|
|
targetLocale = 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 ("${code}") file: `, e)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
|
|
try {
|
|
const englishFilePath = path.join(process.cwd(), 'app', '_locales', 'en', 'messages.json')
|
|
englishLocale = 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(' verifying whether all your locale ("${code}") strings are contained in the english one')
|
|
const extraItems = compareLocalesForMissingItems({ base: targetLocale, subject: englishLocale })
|
|
// console.log('\n verifying whether your locale ("${code}") contains all english strings')
|
|
const missingItems = compareLocalesForMissingItems({ base: englishLocale, subject: targetLocale })
|
|
|
|
const englishEntryCount = Object.keys(englishLocale).length
|
|
const coveragePercent = 100 * (englishEntryCount - missingItems.length) / englishEntryCount
|
|
|
|
console.log(`Status of **${name} (${code})** ${coveragePercent.toFixed(2)}% coverage:`)
|
|
|
|
if (extraItems.length) {
|
|
console.log('\nExtra items that should not be localized:')
|
|
extraItems.forEach(function (key) {
|
|
console.log(` - [ ] ${key}`)
|
|
})
|
|
} else {
|
|
// console.log(` all ${counter} strings declared in your locale ("${code}") were found in the english one`)
|
|
}
|
|
|
|
if (missingItems.length) {
|
|
console.log(`\nMissing items not present in localized file:`)
|
|
missingItems.forEach(function (key) {
|
|
console.log(` - [ ] ${key}`)
|
|
})
|
|
} else {
|
|
// console.log(` all ${counter} english strings were found in your locale ("${code}")!`)
|
|
}
|
|
|
|
if (!extraItems.length && !missingItems.length) {
|
|
console.log('Full coverage : )')
|
|
}
|
|
}
|
|
|
|
function compareLocalesForMissingItems ({ base, subject }) {
|
|
return Object.keys(base).filter((key) => !subject[key])
|
|
}
|