Skip to content

Commit

Permalink
Merge pull request #447 from simplabs/fix-error-nested-translations
Browse files Browse the repository at this point in the history
Add additional guard to check if at the top of the parent tree and tests
  • Loading branch information
Mikek2252 authored Mar 11, 2022
2 parents f2501e2 + e8cd367 commit 6851951
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion __snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ exports[`Test Fixtures remove-unused-translations-nested 1`] = `
[3/4] ⚙️ Checking for unused translations...
[4/4] ⚙️ Checking for missing translations...
⚠️ Found 3 unused translations!
⚠️ Found 4 unused translations!
- foo (used in de.json and en.json)
- extra (used in de.json)
- parent.child.unusedKey (used in de.json and en.json)
- unusedParent.unusedChild.unusedKey (used in de.json and en.json)
👏 No missing translations were found!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"unusedKey": "unused Key",
},
"secondChild": "usedKey"
},
"unusedParent": {
"unusedChild": {
"unusedKey": "unused Key",
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"unusedKey": "unused Key",
},
"secondChild": "usedKey"
},
"unusedParent": {
"unusedChild": {
"unusedKey": "unused Key",
}
}
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function deleteNestedTranslation(file, translationKey, isFullPath = false) {
//Check if this object has another translations if not delete the key.
if (Object.keys(translationParent[attributeKey]).length === 0 || isFullPath) {
delete translationParent[attributeKey];
if (objectKeys.length) {
if (objectKeys.length > 0 && translationParentKeys.length > 0) {
let parentKey = translationParentKeys.join('.');
//continue to travel up parents to remove empty translation key objects.
deleteNestedTranslation(file, parentKey);
Expand Down

0 comments on commit 6851951

Please sign in to comment.