mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #13191 from overleaf/mj-translate-danish
[web] Add missing danish translations GitOrigin-RevId: e430238b498100e2ccb50aff443b9b28f22368b6
This commit is contained in:
parent
f9a7ede032
commit
a702d00477
2 changed files with 1124 additions and 308 deletions
File diff suppressed because it is too large
Load diff
61
services/web/scripts/translations/checkVariables.js
Normal file
61
services/web/scripts/translations/checkVariables.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Usage: node checkVariables.js <locale>
|
||||
|
||||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
const GLOBALS = ['__appName__']
|
||||
const LOCALES = Path.join(__dirname, '../../locales')
|
||||
const baseLocalePath = Path.join(LOCALES, 'en.json')
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.error('Usage: node checkVariables.js <locale>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const localeName = process.argv[2]
|
||||
const localePath = Path.join(LOCALES, `${localeName}.json`)
|
||||
|
||||
const baseLocale = JSON.parse(fs.readFileSync(baseLocalePath, 'utf-8'))
|
||||
const locale = JSON.parse(fs.readFileSync(localePath, 'utf-8'))
|
||||
|
||||
function fetchKeys(str) {
|
||||
const matches = str.matchAll(/__.*?__/g)
|
||||
if (matches.length === 0) {
|
||||
return []
|
||||
}
|
||||
return Array.from(matches).map(match => match[0])
|
||||
}
|
||||
|
||||
function difference(base, target) {
|
||||
const keysInBaseButNotInTarget = base.filter(key => !target.includes(key))
|
||||
const keysInTargetButNotInBase = target.filter(
|
||||
key => !base.includes(key) && !GLOBALS.includes(key)
|
||||
)
|
||||
return {
|
||||
keysInBaseButNotInTarget,
|
||||
keysInTargetButNotInBase,
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(locale)) {
|
||||
if (Object.prototype.hasOwnProperty.call(baseLocale, key)) {
|
||||
const keysInTranslation = fetchKeys(locale[key])
|
||||
const keysInBase = fetchKeys(baseLocale[key])
|
||||
const { keysInBaseButNotInTarget, keysInTargetButNotInBase } = difference(
|
||||
keysInBase,
|
||||
keysInTranslation
|
||||
)
|
||||
if (keysInBaseButNotInTarget.length) {
|
||||
console.warn(
|
||||
`Warning: Missing variables in key ${key}:`,
|
||||
keysInBaseButNotInTarget
|
||||
)
|
||||
}
|
||||
if (keysInTargetButNotInBase.length) {
|
||||
console.warn(
|
||||
`Warning: Extra variables in key ${key}:`,
|
||||
keysInTargetButNotInBase
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue