Skip to content

Commit

Permalink
chore: validate plurals in strings.xml | FC-55 (#348)
Browse files Browse the repository at this point in the history
* chore: validate plurals in strings.xml

* fix: more plurals fixes on English
  • Loading branch information
OmarIthawi authored Jun 21, 2024
1 parent 05c3544 commit 7ff0ff4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/validate-english-strings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Validate English strings.xml

on:
pull_request: { }
push:
branches: [ main, develop ]

jobs:
translation_strings:
name: Validate strings.xml
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install translations requirements
run: make translation_requirements

- name: Validate English plurals in strings.xml
run: make validate_english_plurals

- name: Test extract strings
run: |
make extract_translations
# Ensure the file is extracted
test -f i18n/src/main/res/values/strings.xml
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ pull_translations: clean_translations_temp_directory

extract_translations: clean_translations_temp_directory
python3 i18n_scripts/translation.py --combine

validate_english_plurals:
@if git grep 'quantity' -- '**/res/values/strings.xml' | grep -E 'quantity=.(zero|two|few|many)'; then \
echo ""; \
echo ""; \
echo "Error: Found invalid plurals in the files listed above."; \
echo " Please only use 'one' and 'other' in English strings.xml files,"; \
echo " otherwise Transifex fails to parse them."; \
echo ""; \
exit 1; \
else \
echo "strings.xml files are valid."; \
fi
8 changes: 0 additions & 8 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,11 @@
<string name="core_date_format_assignment_due_tomorrow" tools:ignore="MissingTranslation">Due Tomorrow</string>
<string name="core_date_format_assignment_due_yesterday" tools:ignore="MissingTranslation">Due Yesterday</string>
<plurals name="core_date_format_assignment_due_days_ago" tools:ignore="MissingTranslation">
<item quantity="zero">Due %1$d days ago</item>
<item quantity="one">Due %1$d day ago</item>
<item quantity="two">Due %1$d days ago</item>
<item quantity="few">Due %1$d days ago</item>
<item quantity="many">Due %1$d days ago</item>
<item quantity="other">Due %1$d days ago</item>
</plurals>
<plurals name="core_date_format_assignment_due_in" tools:ignore="MissingTranslation">
<item quantity="zero">Due in %1$d days</item>
<item quantity="one">Due in %1$d day</item>
<item quantity="two">Due in %1$d days</item>
<item quantity="few">Due in %1$d days</item>
<item quantity="many">Due in %1$d days</item>
<item quantity="other">Due in %1$d days</item>
</plurals>
<plurals name="core_date_items_hidden" tools:ignore="MissingTranslation">
Expand Down
4 changes: 0 additions & 4 deletions course/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@
<string name="course_subsection_assignment_info" translatable="false">%1$s - %2$s - %3$d / %4$d</string>

<plurals name="course_assignments_complete" tools:ignore="MissingTranslation">
<item quantity="zero">%1$s of %2$s assignments complete</item>
<item quantity="one">%1$s of %2$s assignment complete</item>
<item quantity="two">%1$s of %2$s assignments complete</item>
<item quantity="few">%1$s of %2$s assignments complete</item>
<item quantity="many">%1$s of %2$s assignments complete</item>
<item quantity="other">%1$s of %2$s assignments complete</item>
</plurals>

Expand Down
4 changes: 0 additions & 4 deletions dashboard/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
<string name="dashboard_no_status_courses">No %1$s Courses</string>

<plurals name="dashboard_past_due_assignment">
<item quantity="zero">%1$d Past Due Assignments</item>
<item quantity="one">%1$d Past Due Assignment</item>
<item quantity="two">%1$d Past Due Assignments</item>
<item quantity="few">%1$d Past Due Assignments</item>
<item quantity="many">%1$d Past Due Assignments</item>
<item quantity="other">%1$d Past Due Assignments</item>
</plurals>
</resources>

0 comments on commit 7ff0ff4

Please sign in to comment.