aissat / easy_localization

Easy and Fast internationalizing your Flutter Apps
https://pub.dev/packages/easy_localization
MIT License
908 stars 325 forks source link

Determine plural cases based on the actual language rules #620

Closed dimach1977 closed 10 months ago

dimach1977 commented 1 year ago

Currently language-specific rules are ignored and all localizations are assumed to have, for example, a binary case ("two") even when it isn't needed. This breaks compatibility with localization management tools that do know which languages should have which plural cases and don't provide a way to add unneeded cases.

dimach1977 commented 1 year ago

To expand a bit. For example, in Russian and other Slavic languages, there's no need for a special "two" form (and the language specific rule here never returns PluralCase.TWO.)

Localization management tools, such as poeditor, will prompt to create only the language-specific plural cases. Thus it would be impossible to create a proper localization for Slavic languages: easy_localization would look for the "two" entry and if that isn't found would default to the "many" form instead of the "few", like it should. This result in strings like "2 дней".

dimach1977 commented 1 year ago

Added tests. Note that there's existing test that encode incorrect behavior or that test for behavior irrelevant to the test (e.g. widget tests checking for specific plurals.) Update those too.

CarlosVimos commented 10 months ago

Hi,

I'm encountering an issue with the pluralization rules for the Polish language in the _pl_rule() function. According to the function definition:

PluralCase

_pl_rule() {
// ...
if (_v == 0 && _i % 10 >= 2 && _i % 10 <= 4 && (_i % 100 < 12 || _i % 100 > 14)) {
return FEW;
// ...
}

This should return the plural form FEW for numbers like 2, 3, 4, 22, 23, 24, and so on (excluding 12, 13, and 14). However, in my testing, it appears that number "2" is instead being categorized under OTHER.

Could this be a potential issue in the pluralization logic, or am I possibly missing something in my setup? I'm using version 3.0.3 of easy_localization.

Would this PR also solve this problem?

bw-flagship commented 10 months ago

@dimach1977 Could you remove the not-referenced function and update the branch? Then we can merge :)

dimach1977 commented 10 months ago

@bw-flagship Done (+cleaned up some copy-pasta in other tests)

bw-flagship commented 10 months ago

There is a problem with the CI-Pipeline, we need to merge #631 first

bw-flagship commented 10 months ago

@dimach1977 there are some analyzer issues:

warning • The '!' will have no effect because the receiver can't be null • lib/src/localization.dart:141:55 • unnecessary_non_null_assertion
   info • Unused import: 'dart:async' • test/easy_localization_language_specific_test.dart:1:8 • unused_import
   info • Unused import: 'package:easy_localization/easy_localization.dart' • test/easy_localization_language_specific_test.dart:4:8 • unused_import
   info • Unused import: 'package:easy_logger/easy_logger.dart' • test/easy_localization_language_specific_test.dart:7:8 • unused_import
   info • Unused import: 'package:shared_preferences/shared_preferences.dart' • test/easy_localization_language_specific_test.dart:10:8 • unused_import
   info • Unused import: 'dart:async' • test/easy_localization_logger_test.dart:1:8 • unused_import
   info • Unused import: 'easy_localization_test.dart' • test/easy_localization_logger_test.dart:7:8 • unused_import
   info • Unused import: 'dart:async' • test/easy_localization_test.dart:1:8 • unused_import
dimach1977 commented 10 months ago

@bw-flagship ✅