From a9a3ac7ecf0010bd037087f2b95325a7afe43caa Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 14:59:44 +0100 Subject: [PATCH 1/6] Look up @_lint_rules in the right dictionary --- check_strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_strings.py b/check_strings.py index b34d8eeb..76713810 100755 --- a/check_strings.py +++ b/check_strings.py @@ -99,7 +99,7 @@ with open(target, encoding='utf-8') as f: strings = {k: v for k, v in values.items() if not k.startswith("@")} print(target, f"- checking {len(strings)} strings") -lint_strings(strings, strings.get("@_lint_rules", {})) +lint_strings(strings, values.get("@_lint_rules", {})) check_duplicate_values(strings) if errors: From 7462f0f0b7d5ee97a87b626ffa481abd09c04d1d Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 15:20:31 +0100 Subject: [PATCH 2/6] Make punctuation customizable per language --- check_strings.py | 10 ++++++---- lib/l10n/app_ja.arb | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/check_strings.py b/check_strings.py index 76713810..6addc898 100755 --- a/check_strings.py +++ b/check_strings.py @@ -40,7 +40,7 @@ def check_duplicate_values(strings): seen[v] = k -def check_prefixes(k, v, s_max_words, s_max_len): +def check_prefixes(k, v, s_max_words, s_max_len, punctuation, q_endings): errs = [] if k.startswith("s_"): if len(v) > s_max_len: @@ -53,11 +53,11 @@ def check_prefixes(k, v, s_max_words, s_max_len): if ". " in v: errs.append("Spans multiple sentences") elif k.startswith("p_"): - if v[-1] not in ".!": + if punctuation and not any(v.endswith(p) for p in punctuation): errs.append("Doesn't end in punctuation") elif k.startswith("q_"): - if not v.endswith("?"): - errs.append("Doesn't end in '?'") + if q_endings and not any(v.endswith(q) for q in q_endings): + errs.append("Doesn't end in question mark.") return errs @@ -79,6 +79,8 @@ def lint_strings(strings, rules): v, rules.get("s_max_words", 4), rules.get("s_max_len", 32), + rules.get("punctuation", [".", "!"]), + rules.get("q_endings", ["?"]), ) ) errs.extend(check_misc(k, v)) diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 967772d8..42c0d697 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -16,6 +16,8 @@ }, "@_lint_rules": { + "punctuation": ["。", "!"], + "q_endings": ["?", "?"], "s_max_words": 4, "s_max_length": 32 }, From b89d6288094a6f706225a6a5a3968fdb5bbbbf90 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 15:29:21 +0100 Subject: [PATCH 3/6] Rename @_lint_rules.punctuation to p_endings Since this lint is specifically about punctuation appropriate for ending a sentence. --- check_strings.py | 6 +++--- lib/l10n/app_ja.arb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/check_strings.py b/check_strings.py index 6addc898..e68e9b7f 100755 --- a/check_strings.py +++ b/check_strings.py @@ -40,7 +40,7 @@ def check_duplicate_values(strings): seen[v] = k -def check_prefixes(k, v, s_max_words, s_max_len, punctuation, q_endings): +def check_prefixes(k, v, s_max_words, s_max_len, p_endings, q_endings): errs = [] if k.startswith("s_"): if len(v) > s_max_len: @@ -53,7 +53,7 @@ def check_prefixes(k, v, s_max_words, s_max_len, punctuation, q_endings): if ". " in v: errs.append("Spans multiple sentences") elif k.startswith("p_"): - if punctuation and not any(v.endswith(p) for p in punctuation): + if p_endings and not any(v.endswith(p) for p in p_endings): errs.append("Doesn't end in punctuation") elif k.startswith("q_"): if q_endings and not any(v.endswith(q) for q in q_endings): @@ -79,7 +79,7 @@ def lint_strings(strings, rules): v, rules.get("s_max_words", 4), rules.get("s_max_len", 32), - rules.get("punctuation", [".", "!"]), + rules.get("p_endings", [".", "!"]), rules.get("q_endings", ["?"]), ) ) diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 42c0d697..a83dd56f 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -16,7 +16,7 @@ }, "@_lint_rules": { - "punctuation": ["。", "!"], + "p_endings": ["。", "!"], "q_endings": ["?", "?"], "s_max_words": 4, "s_max_length": 32 From 97265d24db1e7b8d77d18cdc31d7140665900222 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 15:31:19 +0100 Subject: [PATCH 4/6] Add default p_endings and q_endings to app_en.arb --- lib/l10n/app_en.arb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 08bd17d1..af3dfa42 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -16,6 +16,8 @@ }, "@_lint_rules": { + "p_endings": [".", "!"], + "q_endings": ["?"], "s_max_words": 4, "s_max_length": 32 }, From d5a59392c03bfe58bc02ef5ae309b8ade0374c42 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 16:13:08 +0100 Subject: [PATCH 5/6] Use strings for lint punctuation customization This will be needed for this to be compatible with the JSON-based ARB reformatter, which requires all lists to be of equal length in order for whitespace to line up. --- check_strings.py | 10 +++++----- lib/l10n/app_en.arb | 4 ++-- lib/l10n/app_ja.arb | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/check_strings.py b/check_strings.py index e68e9b7f..17333ef3 100755 --- a/check_strings.py +++ b/check_strings.py @@ -40,7 +40,7 @@ def check_duplicate_values(strings): seen[v] = k -def check_prefixes(k, v, s_max_words, s_max_len, p_endings, q_endings): +def check_prefixes(k, v, s_max_words, s_max_len, p_ending_chars, q_ending_chars): errs = [] if k.startswith("s_"): if len(v) > s_max_len: @@ -53,10 +53,10 @@ def check_prefixes(k, v, s_max_words, s_max_len, p_endings, q_endings): if ". " in v: errs.append("Spans multiple sentences") elif k.startswith("p_"): - if p_endings and not any(v.endswith(p) for p in p_endings): + if p_ending_chars and not any(v.endswith(p) for p in p_ending_chars): errs.append("Doesn't end in punctuation") elif k.startswith("q_"): - if q_endings and not any(v.endswith(q) for q in q_endings): + if q_ending_chars and not any(v.endswith(q) for q in q_ending_chars): errs.append("Doesn't end in question mark.") return errs @@ -79,8 +79,8 @@ def lint_strings(strings, rules): v, rules.get("s_max_words", 4), rules.get("s_max_len", 32), - rules.get("p_endings", [".", "!"]), - rules.get("q_endings", ["?"]), + rules.get("p_ending_chars", ".!"), + rules.get("q_ending_chars", "?"), ) ) errs.extend(check_misc(k, v)) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index af3dfa42..94cc7c3f 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -16,8 +16,8 @@ }, "@_lint_rules": { - "p_endings": [".", "!"], - "q_endings": ["?"], + "p_ending_chars": ".!", + "q_ending_chars": "?", "s_max_words": 4, "s_max_length": 32 }, diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index a83dd56f..e3b840f4 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -16,8 +16,8 @@ }, "@_lint_rules": { - "p_endings": ["。", "!"], - "q_endings": ["?", "?"], + "p_ending_chars": "。!", + "q_ending_chars": "?", "s_max_words": 4, "s_max_length": 32 }, From 88a52f2d95ac392e76351e2c25a35375eb0a5293 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Thu, 2 Nov 2023 16:28:28 +0100 Subject: [PATCH 6/6] Restore lost question mark option in app_ja.arb --- lib/l10n/app_ja.arb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index e3b840f4..11eb2a06 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -17,7 +17,7 @@ "@_lint_rules": { "p_ending_chars": "。!", - "q_ending_chars": "?", + "q_ending_chars": "??", "s_max_words": 4, "s_max_length": 32 },