mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #3315 from overleaf/jpa-i18n-transform-locales
[misc] i18n: transform locales GitOrigin-RevId: 2306682eab2b10a69c14520cb22338d8537397cd
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
This script will aid the process of inserting HTML fragments into all the
|
||||
locales.
|
||||
We are migrating from
|
||||
locale: 'PRE __key1__ POST'
|
||||
pug: translate(localeKey, { key1: '<b>VALUE</b>' })
|
||||
to
|
||||
locale: 'PRE <0>__key1__</0> POST'
|
||||
pug: translate(localeKey, { key1: 'VALUE' }, ['b'])
|
||||
|
||||
|
||||
MAPPING entries:
|
||||
localeKey: ['key1', 'key2']
|
||||
click_here_to_view_sl_in_lng: ['lngName']
|
||||
*/
|
||||
const MAPPING = {}
|
||||
|
||||
const { transformLocales } = require('./transformLocales')
|
||||
|
||||
function transformLocale(locale, components) {
|
||||
components.forEach((key, idx) => {
|
||||
const i18nKey = `__${key}__`
|
||||
const replacement = `<${idx}>${i18nKey}</${idx}>`
|
||||
if (!locale.includes(replacement)) {
|
||||
locale = locale.replace(new RegExp(i18nKey, 'g'), replacement)
|
||||
}
|
||||
})
|
||||
return locale
|
||||
}
|
||||
|
||||
function main() {
|
||||
transformLocales(MAPPING, transformLocale)
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main()
|
||||
}
|
||||
Reference in New Issue
Block a user