1
0
Fork 0

Merge pull request #2469 from eriese/eriese-reconfigure

Fix: copy locale files to the sites in prebuild
This commit is contained in:
Joost De Cock 2022-07-24 21:29:33 +02:00 committed by GitHub
commit 686d1d6304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View file

@ -1,4 +1,7 @@
import {build} from '../src/prebuild.mjs' import {build} from '../src/prebuild.mjs'
// use a deny-list to keep locales that aren't ready out of the build
export const denyList = ['uk']
// call this here instead of in the src/prebuild.mjs so that build isn't called by other files importing that build function // call this here instead of in the src/prebuild.mjs so that build isn't called by other files importing that build function
build() build((loc) => denyList.indexOf(loc) === -1)

View file

@ -220,6 +220,7 @@ export const build = async (localeFilter = () => true, only=false) => {
const namespaces = await getNamespacesFromFileList(files, locales, only) const namespaces = await getNamespacesFromFileList(files, locales, only)
await writeFiles(namespaces) await writeFiles(namespaces)
return namespaces
} }
//export default strings //export default strings

View file

@ -1,5 +1,39 @@
import {build} from '../../../packages/i18n/src/prebuild.mjs' import {build} from '../../../packages/i18n/src/prebuild.mjs'
import {denyList} from '../../../packages/i18n/scripts/prebuilder.mjs'
import fs from 'fs'
import path from 'path'
export const prebuildI18n = async(site, only=false) => { export const prebuildI18n = async(site, only=false) => {
build((loc) => site !== 'dev' || loc === 'en', only) const writeJson = async (locale, namespace, content) => fs.writeFileSync(
path.resolve(
'..',
site,
'public',
'locales',
locale,
`${namespace}.json`
),
JSON.stringify(content)
)
const filter = site === 'dev' ? (loc => lock === 'en') : (loc => denyList.indexOf(loc) === -1)
const locales = await build(filter, only)
console.log (`copying them to ${site}`, Object.keys(locales))
const languages = {}
Object.keys(locales).forEach(l => languages[l] = locales[l].i18n[l])
for (const locale in locales) {
// Only English for dev site
const loc = locales[locale]
// Fan out into namespaces
for (const namespace in loc) {
writeJson(
locale, namespace,
loc[namespace]
)
}
writeJson(locale, 'locales', languages)
}
} }