π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Tighten mobile localization linting
Manav Rathib60661c261fd
diff --git a/.github/workflows/auth-lint.yml b/.github/workflows/auth-lint.ymlindex aca388bf21..125857ecde 100644--- a/.github/workflows/auth-lint.yml+++ b/.github/workflows/auth-lint.yml@@ -6,6 +6,7 @@ on:paths:- "mobile/apps/auth/**"- ".github/workflows/auth-lint.yml"+ - "mobile/scripts/check_source_arb_plurals.rb"env:FLUTTER_VERSION: "3.32.8"@@ -29,6 +30,10 @@ jobs:run: ruby mobile/scripts/check_frozen_pubspecs.rb mobile/apps/authworking-directory: ${{ github.workspace }}+ - name: Verify source ARB plurals+ run: ruby mobile/scripts/check_source_arb_plurals.rb+ working-directory: ${{ github.workspace }}+- name: Verify custom icons are lowercase including optional understores, and end with .svgrun: |find assets/custom-icons -type f -name "*.svg" | while read -r file; dodiff --git a/.github/workflows/locker-lint.yml b/.github/workflows/locker-lint.ymlindex c6324fc822..a357ce0755 100644--- a/.github/workflows/locker-lint.yml+++ b/.github/workflows/locker-lint.yml@@ -10,6 +10,7 @@ on:- "mobile/packages/rust/**"- "mobile/packages/sharing/**"- ".github/workflows/locker-lint.yml"+ - "mobile/scripts/check_source_arb_plurals.rb"env:FLUTTER_VERSION: "3.32.8"@@ -32,6 +33,10 @@ jobs:run: ruby mobile/scripts/check_frozen_pubspecs.rb mobile/apps/lockerworking-directory: ${{ github.workspace }}+ - name: Verify source ARB plurals+ run: ruby mobile/scripts/check_source_arb_plurals.rb+ working-directory: ${{ github.workspace }}+- name: Install Flutter ${{ env.FLUTTER_VERSION }}uses: subosito/flutter-action@v2with:diff --git a/.github/workflows/mobile-crowdin-sync.yml b/.github/workflows/mobile-crowdin-sync.ymlindex c688b966f4..457bdf385f 100644--- a/.github/workflows/mobile-crowdin-sync.yml+++ b/.github/workflows/mobile-crowdin-sync.yml@@ -34,7 +34,7 @@ jobs:base_path: "mobile/apps/photos/"config: "mobile/apps/photos/crowdin.yml"project_id: 574741- localization_branch_name: translations/mobile+ localization_branch_name: translations/photospull_request_title: "[mobile/photos] New translations"pull_request_body: "New translations from [Crowdin](https://crowdin.com/project/ente-photos-app)"- app: authdiff --git a/.github/workflows/mobile-lint.yml b/.github/workflows/mobile-lint.ymlindex e23600d2aa..9056ba1900 100644--- a/.github/workflows/mobile-lint.yml+++ b/.github/workflows/mobile-lint.yml@@ -9,6 +9,7 @@ on:- "rust/photos/**"- "rust/core/**"- ".github/workflows/mobile-lint.yml"+ - "mobile/scripts/check_source_arb_plurals.rb"env:FLUTTER_VERSION: "3.32.8"@@ -32,6 +33,10 @@ jobs:run: ruby mobile/scripts/check_frozen_pubspecs.rb mobile/apps/photosworking-directory: ${{ github.workspace }}+ - name: Verify source ARB plurals+ run: ruby mobile/scripts/check_source_arb_plurals.rb+ working-directory: ${{ github.workspace }}+- name: Install Flutter ${{ env.FLUTTER_VERSION }}uses: subosito/flutter-action@v2with:diff --git a/.github/workflows/mobile-packages-lint.yml b/.github/workflows/mobile-packages-lint.ymlindex 0576fb84d8..aa46a16d64 100644--- a/.github/workflows/mobile-packages-lint.yml+++ b/.github/workflows/mobile-packages-lint.yml@@ -10,6 +10,7 @@ on:- "rust/photos/**"- ".github/workflows/mobile-packages-lint.yml"- "mobile/scripts/check_frozen_pubspecs.rb"+ - "mobile/scripts/check_source_arb_plurals.rb"- ".github/scripts/get-affected-packages.sh"- "mobile/analysis_options.yaml"# Allow manual trigger for testing@@ -102,6 +103,9 @@ jobs:- name: Verify frozen mobile pubspecsrun: ruby mobile/scripts/check_frozen_pubspecs.rb mobile+ - name: Verify source ARB plurals+ run: ruby mobile/scripts/check_source_arb_plurals.rb+packages-lint:needs: detect-changesruns-on: ubuntu-latestdiff --git a/mobile/apps/photos/docs/translations.md b/mobile/apps/photos/docs/translations.mdindex a7810705ef..0b03b7f129 100644--- a/mobile/apps/photos/docs/translations.md+++ b/mobile/apps/photos/docs/translations.md@@ -67,6 +67,16 @@ of the developers (i.e. [laurenspriem](https://github.com/laurenspriem))1. After the PR is merged, the source-push workflow will upload new sourcestrings to Crowdin's dashboard, allowing translators to translate it.+## Plurals++Use plural categories `one` and `other` in source ARBs, not `=1`.++```json+"photosCount": "{count, plural, =0{No photos} one{{count} photo} other{{count} photos}}"+```++`=0`, `one`, and `other` can be used together. Exact selectors win first; `one` is a locale category, not always exactly `1`. When showing the number in the `one` branch, use the count placeholder instead of hardcoding `1`.+## Updating an existing string1. Update the existing value for the key in the source `intl_en.arb`.diff --git a/mobile/scripts/check_source_arb_plurals.rb b/mobile/scripts/check_source_arb_plurals.rbnew file mode 100644index 0000000000..ef2769233b--- /dev/null+++ b/mobile/scripts/check_source_arb_plurals.rb@@ -0,0 +1,47 @@+#!/usr/bin/env ruby++require "json"+require "yaml"++MOBILE_ROOT = File.expand_path("..", __dir__)+EXACT_ONE_SELECTOR = /=1\s*\{/.freeze++def source_arbs+ Dir[File.join(MOBILE_ROOT, "{apps,packages}/**/l10n.yaml")].sort.map do |config_path|+ config = YAML.load_file(config_path) || {}+ arb_dir = config["arb-dir"]+ template_arb_file = config["template-arb-file"]+ next unless arb_dir.is_a?(String) && template_arb_file.is_a?(String)++ File.join(File.dirname(config_path), arb_dir, template_arb_file)+ end.compact.uniq+end++def display_path(path)+ "mobile/#{path.delete_prefix("#{MOBILE_ROOT}/")}"+end++errors = []++source_arbs.each do |arb_path|+ arb = JSON.parse(File.read(arb_path))++ arb.each do |key, value|+ next if key.start_with?("@")+ next unless value.is_a?(String)+ next unless value.match?(EXACT_ONE_SELECTOR)++ errors << "#{display_path(arb_path)}: #{key} uses =1. Use one{...} in source ARBs; keep exact selectors for cases like =0."+ end+rescue JSON::ParserError => e+ errors << "#{display_path(arb_path)}: invalid JSON: #{e.message}"+end++if errors.empty?+ puts "Verified source ARB plurals."+ exit 0+end++warn "Source ARB plural violations:"+errors.each { |error| warn " - #{error}" }+exit 1