-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3584 from thematters/develop
Release: v4.25.0
- Loading branch information
Showing
78 changed files
with
6,943 additions
and
2,910 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs') | ||
|
||
const sort = (o) => { | ||
return Object.keys(o) | ||
.sort() | ||
.reduce((r, k) => ((r[k] = o[k]), r), {}) | ||
} | ||
|
||
const generate = (source, target) => { | ||
const newTarget = { ...target } | ||
|
||
// Finding keys missing in target and copying them from source | ||
for (let key in source) { | ||
if (!target.hasOwnProperty(key)) { | ||
newTarget[key] = source[key] | ||
} | ||
} | ||
|
||
// Removing keys missing in source from target | ||
for (let key in target) { | ||
if (!source.hasOwnProperty(key)) { | ||
delete newTarget[key] | ||
} | ||
} | ||
|
||
return sort(newTarget) | ||
} | ||
|
||
// read source file | ||
const source = JSON.parse(fs.readFileSync('./lang/default.json', 'utf8')) | ||
|
||
// read target file | ||
const locales = ['zh-Hant', 'zh-Hans', 'en'] | ||
const target = {} | ||
for (let locale of locales) { | ||
target[locale] = JSON.parse(fs.readFileSync(`./lang/${locale}.json`, 'utf8')) | ||
} | ||
|
||
// genearte new target file | ||
for (let locale of locales) { | ||
fs.writeFileSync( | ||
`./lang/${locale}.json`, | ||
JSON.stringify(generate(source, target[locale]), null, 2), | ||
'utf8' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.