Merge pull request #1246 from Yubico/lint-check-keys

Check that translation keys exist in app_en.arb in translation linter
This commit is contained in:
Emil Lundberg 2023-11-02 17:06:36 +01:00 committed by GitHub
commit 96d17b81f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,8 +15,9 @@
# limitations under the License.
import sys
import json
import os
import sys
errors = []
@ -70,6 +71,14 @@ def check_misc(k, v):
return errs
def check_keys_exist_in_reference(reference_strings, checked_strings):
errs = []
for key in checked_strings.keys():
if key not in reference_strings:
errs.append(f"Invalid key: {key}")
return errs
def lint_strings(strings, rules):
for k, v in strings.items():
if v is None:
@ -106,6 +115,11 @@ print(target, f"- checking {len(strings)} strings")
lint_strings(strings, values.get("@_lint_rules", {}))
check_duplicate_values(strings)
with open(os.path.join(os.path.dirname(target), 'app_en.arb'), encoding='utf-8') as f:
reference_values = json.load(f)
errors.extend(check_keys_exist_in_reference(reference_values, values))
if errors:
print()
print(target, "HAS ERRORS:")