mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Require English descriptions in locale files (#10260)
The `verify-locale-strings.js` script now validates that the descriptions from the `en` locale are also present in all other locales. These descriptions are intended to help with translation, and are not meant to be translated. This check will ensure that translators don't accidentally translate these. It also ensures they're present alongside each translated message, which might be helpful for understanding context.
This commit is contained in:
parent
b98cef16af
commit
181bd7bc16
@ -37,7 +37,17 @@ function compareLocalesForMissingItems({ base, subject }) {
|
||||
return Object.keys(base).filter((key) => !subject[key])
|
||||
}
|
||||
|
||||
function compareLocalesForMissingDescriptions({ englishLocale, targetLocale }) {
|
||||
return Object.keys(englishLocale).filter(
|
||||
(key) =>
|
||||
targetLocale[key] !== undefined &&
|
||||
englishLocale[key].description !== undefined &&
|
||||
englishLocale[key].description !== targetLocale[key].description,
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compareLocalesForMissingDescriptions,
|
||||
compareLocalesForMissingItems,
|
||||
getLocale,
|
||||
getLocalePath,
|
||||
|
@ -8,7 +8,8 @@
|
||||
//
|
||||
// This script will validate that locales have no unused messages. It will check
|
||||
// the English locale against string literals found under `ui/`, and it will check
|
||||
// other locales by comparing them to the English locale.
|
||||
// other locales by comparing them to the English locale. It will also validate
|
||||
// that non-English locales have all descriptions present in the English locale.
|
||||
//
|
||||
// A report will be printed to the console detailing any unused messages.
|
||||
//
|
||||
@ -27,6 +28,7 @@ const log = require('loglevel')
|
||||
const matchAll = require('string.prototype.matchall').getPolyfill()
|
||||
const localeIndex = require('../app/_locales/index.json')
|
||||
const {
|
||||
compareLocalesForMissingDescriptions,
|
||||
compareLocalesForMissingItems,
|
||||
getLocale,
|
||||
getLocalePath,
|
||||
@ -129,12 +131,32 @@ async function verifyLocale(code) {
|
||||
})
|
||||
}
|
||||
|
||||
if (extraItems.length > 0) {
|
||||
const missingDescriptions = compareLocalesForMissingDescriptions({
|
||||
englishLocale,
|
||||
targetLocale,
|
||||
})
|
||||
|
||||
if (missingDescriptions.length) {
|
||||
console.log(
|
||||
`**${code}**: ${missingDescriptions.length} missing descriptions`,
|
||||
)
|
||||
log.info('Messages with missing descriptions:')
|
||||
missingDescriptions.forEach(function (key) {
|
||||
log.info(` - [ ] ${key}`)
|
||||
})
|
||||
}
|
||||
|
||||
if (extraItems.length > 0 || missingDescriptions.length > 0) {
|
||||
if (fix) {
|
||||
const newLocale = { ...targetLocale }
|
||||
for (const item of extraItems) {
|
||||
delete newLocale[item]
|
||||
}
|
||||
for (const message of Object.keys(englishLocale)) {
|
||||
if (englishLocale[message].description && targetLocale[message]) {
|
||||
targetLocale[message].description = englishLocale[message].description
|
||||
}
|
||||
}
|
||||
await writeLocale(code, newLocale)
|
||||
}
|
||||
return true
|
||||
|
Loading…
Reference in New Issue
Block a user