Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let all locales fall back to en #138

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/data/_fill-missing-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const localesWithMissingContent = require('../locales-with-missing-content')
const { pipe, defaultsDeep, isPlainObject } = require('lodash/fp')
const dataFolder = path.join(__dirname, '../../src/client/static/data')

const keepBackups = false
const keepBackups = true

function convertEmptyStringsToUndefined(obj) {
function convert(value, changeNullToUndefined = false) {
Expand Down Expand Up @@ -43,7 +43,7 @@ function convertEmptyStringsToUndefined(obj) {
// eslint-disable-next-line no-unused-vars
const log = data => {console.log(data); return data}
const files = sourceLocale => glob.sync(`${dataFolder}/${sourceLocale}/**/*.json`)
const getDefaultFile = (sourceLocale, baseLocale) => file => file.replace(sourceLocale, baseLocale)
const getDefaultFile = (sourceLocale, baseLocale) => file => file.replace(`data/${sourceLocale}`, `data/${baseLocale}`)
const readFile = filePath => fs.readFileSync(filePath, { encoding: 'utf-8' })
const getFileContent = pipe(readFile, JSON.parse, convertEmptyStringsToUndefined)
const getDefaultFileContent = (sourceLocale, baseLocale) => filePath => pipe(getDefaultFile(sourceLocale, baseLocale), readFile, JSON.parse)(filePath)
Expand All @@ -54,7 +54,7 @@ const getDefaultFileContent = (sourceLocale, baseLocale) => filePath => pipe(get
]
const mergeDefaultInSource = ([defaultContent, source, filePath]) => ({ content: defaultsDeep(defaultContent, source), filePath })
const writeResult = sourceLocale => ({ content, filePath }) => {
keepBackups && fs.renameSync(filePath, filePath.replace(sourceLocale, `${sourceLocale}_BK`))
keepBackups && fs.renameSync(filePath, filePath.replace(`data/${sourceLocale}`, `data/${sourceLocale}_BK`))
fs.writeFileSync(filePath, JSON.stringify(content, null, 2), { encoding: 'utf-8' })
}

Expand Down
4 changes: 4 additions & 0 deletions config/locales-with-missing-content.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = [
{ sourceLocale: 'en_US', baseLocale: 'en' },
{ sourceLocale: 'nl', baseLocale: 'en' },
{ sourceLocale: 'ru', baseLocale: 'en' },
{ sourceLocale: 'zh_CN', baseLocale: 'en' },
{ sourceLocale: 'es', baseLocale: 'en' },
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nobuild:guide": "build-storybook -c config/storybook -o dist/client/guide/",
"predata": "rimraf src/client/static/data/ src/client/static/_redirects",
"data": "node ./config/data/_dump-dato.js",
"postdata": "node ./config/data/_create-redirects.js && node ./config/data/_build-messages.js & node ./config/data/_fill-missing-content.js",
"postdata": "node ./config/data/_create-redirects.js && node ./config/data/_build-messages.js && node ./config/data/_fill-missing-content.js",
"predev": "rimraf dist/ && npm run data",
"dev": "netlify dev --port 5326 ",
"start": "nuxt",
Expand Down