mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
b441b7cfdc
The report on missing messages has been removed from the verify locales script. This report was making the console output of this command unreasonably long, and would obscure the reports on any invalid entries. A new script was written to report on missing localized messages. This can be run with the command `yarn locale-coverage`. This will print a report to the console on the coverage for each locale.
45 lines
915 B
JavaScript
45 lines
915 B
JavaScript
const path = require('path')
|
|
const fs = require('fs')
|
|
const { promisify } = require('util')
|
|
|
|
const log = require('loglevel')
|
|
|
|
const readFile = promisify(fs.readFile)
|
|
|
|
function getLocalePath(code) {
|
|
return path.resolve(
|
|
__dirname,
|
|
'..',
|
|
'..',
|
|
'app',
|
|
'_locales',
|
|
code,
|
|
'messages.json',
|
|
)
|
|
}
|
|
|
|
async function getLocale(code) {
|
|
try {
|
|
const localeFilePath = getLocalePath(code)
|
|
const fileContents = await readFile(localeFilePath, 'utf8')
|
|
return JSON.parse(fileContents)
|
|
} catch (e) {
|
|
if (e.code === 'ENOENT') {
|
|
log.error('Locale file not found')
|
|
} else {
|
|
log.error(`Error opening your locale ("${code}") file: `, e)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
function compareLocalesForMissingItems({ base, subject }) {
|
|
return Object.keys(base).filter((key) => !subject[key])
|
|
}
|
|
|
|
module.exports = {
|
|
compareLocalesForMissingItems,
|
|
getLocale,
|
|
getLocalePath,
|
|
}
|