-
-
Notifications
You must be signed in to change notification settings - Fork 107
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 #22 from ci010/beta
Not yet Beta Former-commit-id: 7416b03
- Loading branch information
Showing
164 changed files
with
5,261 additions
and
4,262 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
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
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
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
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
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 @@ | ||
add55b074a6f739103f24663b12c8fb351fa77ef |
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 @@ | ||
d4d6614d6f10fdac341be84f84391b06e26ec2ea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,68 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const base = path.resolve(__dirname, '..', 'static', 'locales'); | ||
|
||
const files = fs.readdirSync(base).filter(f => f.endsWith('.json')).map(f => path.join(base, f)); | ||
|
||
function discover(dest, src) { | ||
const keys = Object.keys(src); | ||
for (const k of keys) { | ||
// eslint-disable-next-line no-continue | ||
if (k === '$schema') continue; | ||
const v = src[k]; | ||
if (typeof v === 'object') { | ||
if (!dest[k]) { | ||
dest[k] = {}; | ||
} | ||
discover(dest[k], v); | ||
} else { | ||
dest[k] = ''; | ||
} | ||
} | ||
} | ||
|
||
function generateSchema(o) { | ||
const type = typeof o; | ||
if (type === 'object') { | ||
const keys = Object.keys(o); | ||
return { | ||
type: 'object', | ||
properties: keys.map(k => ({ [k]: generateSchema(o[k]) })).reduce((a, b) => ({ ...a, ...b })), | ||
required: keys, | ||
}; | ||
} | ||
if (type === 'string') { | ||
return { type: 'string' }; | ||
} | ||
throw new Error(o); | ||
} | ||
|
||
function sorted(o) { | ||
const result = {}; | ||
const keys = Object.keys(o).sort(); | ||
for (const key of keys) { | ||
// eslint-disable-next-line no-continue | ||
if (key === '$schema') continue; | ||
if (typeof o[key] === 'object') { | ||
o[key] = sorted(o[key]); | ||
} | ||
result[key] = o[key]; | ||
} | ||
return result; | ||
} | ||
|
||
const powerLang = {}; | ||
Promise.all(files.map(processFile)).then(() => { | ||
const schema = generateSchema(powerLang); | ||
schema.$id = 'https://raw.githubusercontent.com/ci010/VoxeLauncher/master/static/locale.schema.json'; | ||
fs.writeFileSync(path.resolve(__dirname, '..', 'static', 'locale.schema.json'), JSON.stringify(schema, null, 4)); | ||
}); | ||
|
||
async function processFile(f) { | ||
const b = await fs.promises.readFile(f); | ||
const o = JSON.parse(b.toString()); | ||
discover(powerLang, o); | ||
const result = { $schema: '../locale.schema.json', ...sorted(o) }; | ||
await fs.promises.writeFile(f, JSON.stringify(result, null, 4)); | ||
} |
Oops, something went wrong.