Add string checks and Github Actions.

This commit is contained in:
Dain Nilsson 2023-03-02 14:20:47 +01:00
parent b33dca3900
commit 30b9900ca8
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 44 additions and 6 deletions

35
.github/workflows/check-strings.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Check strings
on: [push, pull_request]
jobs:
strings:
runs-on: ubuntu-latest
env:
FLUTTER: '3.7.5'
steps:
- uses: actions/checkout@v3
- name: Ensure main locale is correct
run: python check_strings.py lib/l10n/app_en.arb
- name: Check remaining locales
run: |
find lib/l10n/ -name "app_en.arb" -prune -o -name "*.arb" -print0 | xargs -n 1 -0 ./check_strings.py >> $GITHUB_STEP_SUMMARY || echo "::warning::Problems in locales"
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: ${{ env.FLUTTER }}
- name: Check missing strings
run: |
flutter gen-l10n
if [[ "$(cat missing_l10n_strings.json)" != "{}" ]]; then
echo "::notice::Strings missing in translations"
echo "" >> $GITHUB_STEP_SUMMARY
echo "Missing strings:" >> $GITHUB_STEP_SUMMARY
cat missing_l10n_strings.json >> $GITHUB_STEP_SUMMARY
fi

View File

@ -47,7 +47,7 @@ def check_prefixes(k, v, s_max_words, s_max_len):
errs.append(f"Too long ({len(v)} chars)")
if len(v.split()) > s_max_words:
errs.append(f"Too many words ({len(v.split())})")
elif k.startswith("l_"):
if k.startswith("l_") or k.startswith("s_"):
if v.endswith("."):
errs.append("Ends with '.'")
if ". " in v:
@ -65,6 +65,8 @@ def check_misc(k, v):
errs = []
if "..." in v:
errs.append("'...' should be replaced with '\\u2026'")
if v[0].upper() != v[0]:
errs.append("Starts with lowercase letter")
return errs
@ -96,15 +98,16 @@ with open(target) as f:
strings = {k: v for k, v in values.items() if not k.startswith("@")}
check_duplicate_values(strings)
print(target, f"- checking {len(strings)} strings")
lint_strings(strings, strings.get("@_lint_rules", {}))
print(len(strings), "strings in file")
check_duplicate_values(strings)
if errors:
print()
print(target, "HAS ERRORS:")
for e in errors:
print(e)
print()
sys.exit(1)
print("OK")
print(target, "OK")