overleaf/services/web/scripts/translations/transformLocales.js
Miguel Serrano f2eb4893fe Merge pull request #3315 from overleaf/jpa-i18n-transform-locales
[misc] i18n: transform locales

GitOrigin-RevId: 2306682eab2b10a69c14520cb22338d8537397cd
2020-10-28 03:04:33 +00:00

49 lines
930 B
JavaScript

const fs = require('fs')
const LANGUAGES = [
'cs',
'da',
'de',
'en',
'es',
'fi',
'fr',
'it',
'ja',
'ko',
'nl',
'no',
'pl',
'pt',
'ru',
'sv',
'tr',
'zh-CN'
]
const LOCALES = {}
LANGUAGES.forEach(loadLocales)
function loadLocales(language) {
LOCALES[language] = require(`../../locales/${language}.json`)
}
function transformLocales(mapping, transformLocale) {
Object.entries(LOCALES).forEach(([language, translatedLocales]) => {
Object.entries(mapping).forEach(([localeKey, spec]) => {
const locale = translatedLocales[localeKey]
if (!locale) {
// This locale is not translated yet.
return
}
translatedLocales[localeKey] = transformLocale(locale, spec)
})
fs.writeFileSync(
`${__dirname}/../../locales/${language}.json`,
JSON.stringify(translatedLocales, null, 2) + '\n'
)
})
}
module.exports = {
transformLocales
}