mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
8293771f58
Migrate scripts/translation to esm GitOrigin-RevId: 475ec949f0ba238791df91de109169584e68c701
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
import Path from 'path'
|
|
import fs from 'fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { loadLocale } from './utils.js'
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
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] = loadLocale(language)
|
|
}
|
|
|
|
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'
|
|
)
|
|
})
|
|
}
|
|
|
|
export default {
|
|
transformLocales,
|
|
}
|