overleaf/services/web/scripts/translations/transformLocales.js
Hugh O'Brien f7900b474b Merge pull request #4799 from overleaf/hb-eslint-rules
Re-enable some eslint rules

GitOrigin-RevId: 16153adb839bb61784bb40fbc8e43da281fe090d
2021-09-15 08:03:43 +00:00

50 lines
971 B
JavaScript

const Path = require('path')
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(
Path.join(__dirname, `/../../locales/${language}.json`),
JSON.stringify(translatedLocales, null, 2) + '\n'
)
})
}
module.exports = {
transformLocales,
}