Skip to content

Commit

Permalink
Add: check for extra or misspelled keys
Browse files Browse the repository at this point in the history
  • Loading branch information
nichwall committed Apr 11, 2024
1 parent e41c982 commit 90af59d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ with:
## Example Integration Workflow
This workflow can be used to validate that all language files are alphabetized.
Any language file being out of order will cause the workflow to throw an error.
The workflow will also throw an error if any keys exists in a language file and do not exist in the base file.
```yaml
name: Verify all i18n files are alphabetized

Expand Down
7 changes: 7 additions & 0 deletions copy_keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function updateJSONFiles(baseFileName, directory) {
if (filename.endsWith('.json') && filename !== baseFileName) {
let otherData = loadJSONFile(filePath);

// Check if there are keys in another langague that are not in the base English file
for (const key in otherData) {
if (!(key in sortedBaseData)) {
throw new Error(`Key '${key}' found in '${filename}' but not in '${baseFileName}' file`);
}
}

// Copy missing fields from the base data
for (const key in sortedBaseData) {
if (!(key in otherData)) {
Expand Down
7 changes: 7 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26632,6 +26632,13 @@ function updateJSONFiles(baseFileName, directory) {
if (filename.endsWith('.json') && filename !== baseFileName) {
let otherData = loadJSONFile(filePath);

// Check if there are keys in another langague that are not in the base English file
for (const key in otherData) {
if (!(key in sortedBaseData)) {
throw new Error(`Key '${key}' found in '${filename}' but not in '${baseFileName}' file`);
}
}

// Copy missing fields from the base data
for (const key in sortedBaseData) {
if (!(key in otherData)) {
Expand Down

0 comments on commit 90af59d

Please sign in to comment.