-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: verify locale data * ci: separate workflows * ci: missing installation
- Loading branch information
1 parent
367bf0c
commit 1d4e639
Showing
2 changed files
with
80 additions
and
0 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,27 @@ | ||
name: Lint | ||
|
||
on: | ||
push: | ||
paths: | ||
- locales/** | ||
pull_request: | ||
paths: | ||
- locales/** | ||
|
||
jobs: | ||
locale_verify: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
submodules: true | ||
- uses: pnpm/action-setup@v4 | ||
- uses: actions/[email protected] | ||
with: | ||
node-version-file: '.node-version' | ||
cache: 'pnpm' | ||
- run: corepack enable | ||
- run: pnpm i --frozen-lockfile | ||
- run: cd locales && node verify.js |
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,53 @@ | ||
import locales from './index.js'; | ||
|
||
let valid = true; | ||
|
||
function writeError(type, lang, tree, data) { | ||
process.stderr.write(JSON.stringify({ type, lang, tree, data })); | ||
process.stderr.write('\n'); | ||
valid = false; | ||
} | ||
|
||
function verify(expected, actual, lang, trace) { | ||
for (let key in expected) { | ||
if (!Object.prototype.hasOwnProperty.call(actual, key)) { | ||
continue; | ||
} | ||
if (typeof expected[key] === 'object') { | ||
if (typeof actual[key] !== 'object') { | ||
writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'object', actual: typeof actual[key] }); | ||
continue; | ||
} | ||
verify(expected[key], actual[key], lang, trace ? `${trace}.${key}` : key); | ||
} else if (typeof expected[key] === 'string') { | ||
switch (typeof actual[key]) { | ||
case 'object': | ||
writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'string', actual: 'object' }); | ||
break; | ||
case 'undefined': | ||
continue; | ||
case 'string': | ||
const expectedParameters = new Set(expected[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1))); | ||
const actualParameters = new Set(actual[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1))); | ||
for (let parameter of expectedParameters) { | ||
if (!actualParameters.has(parameter)) { | ||
writeError('missing_parameter', lang, trace ? `${trace}.${key}` : key, { parameter }); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const { ['ja-JP']: original, ...verifiees } = locales; | ||
|
||
for (let lang in verifiees) { | ||
if (!Object.prototype.hasOwnProperty.call(locales, lang)) { | ||
continue; | ||
} | ||
verify(original, verifiees[lang], lang); | ||
} | ||
|
||
if (!valid) { | ||
process.exit(1); | ||
} |