Skip to content

[FEAT] Add CLDR plural form support to localization system#707

Merged
sadespresso merged 1 commit intoflow-mn:developfrom
PawiX25:feat/plural-support
Apr 21, 2026
Merged

[FEAT] Add CLDR plural form support to localization system#707
sadespresso merged 1 commit intoflow-mn:developfrom
PawiX25:feat/plural-support

Conversation

@PawiX25
Copy link
Copy Markdown
Contributor

@PawiX25 PawiX25 commented Apr 19, 2026

Summary

Add CLDR plural form support to the localization system, enabling correct plural forms for all 14 supported languages.

Closes #706

Problem

The current localization system uses a single translation string for numeric values, which results in grammatically incorrect output in languages with complex plural rules. For example, in Polish: "1 transakcji" (incorrect) instead of "1 transakcja" (correct).

Solution

Core changes (lib/l10n/flow_localizations.dart)

  • Track the current locale via _currentLocale static field
  • Add _pluralCategory(num n, String langCode) method implementing CLDR plural rules for all supported languages:
    • pl: one / few / many
    • ru, uk, be: one / few / many (East Slavic rules)
    • cs: one / few / other
    • ar: zero / one / two / few / many / other
    • fr, fa: one (0-1) / other
    • en, de, it, tr, es, mn: one / other
  • When getTransalation() receives a num value, it resolves the CLDR plural category and looks for a suffixed key (e.g., key.one, key.few, key.many) before falling back to the base key

Translation keys

Added plural form keys for transaction counts in 11 language files:

  • tabs.home.transactionsCount.{category}
  • transactions.count.{category}

Languages with plural keys: en, pl, ru, uk, be, cs, ar, it, fr, es, de.
Languages skipped (nouns don't inflect after numbers): tr, mn, fa.

How it works

Translation authors add suffixed keys alongside the base key:

{
  "transactions.count": "{} transakcji",
  "transactions.count.one": "{} transakcja",
  "transactions.count.few": "{} transakcje",
  "transactions.count.many": "{} transakcji"
}

The system automatically selects the correct form based on the numeric value and current locale. If no plural key exists, it falls back to the base key — fully backward compatible.

Testing

  • Verified on device with Polish locale: "1 transakcja", "2 transakcje", "5 transakcji" all display correctly
  • Backward compatible: languages/keys without plural suffixes continue to work unchanged

- Track current locale via _currentLocale static field
- Add _pluralCategory() implementing CLDR plural rules for 14 languages
- When getTransalation() receives a num value, resolve CLDR category
  and look for suffixed key (key.one, key.few, key.many) before fallback
- Add plural form keys for transaction counts in 11 language files
- Update l10n integrity test to handle plural suffix keys
@PawiX25 PawiX25 force-pushed the feat/plural-support branch from bf6df90 to 2aa671d Compare April 20, 2026 00:13
Copy link
Copy Markdown
Collaborator

@sadespresso sadespresso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thank you! the backwards compat is huge.

@sadespresso sadespresso merged commit 48813b7 into flow-mn:develop Apr 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add CLDR plural form support to localization system

2 participants