-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Documentation and Add Comprehensive Pluralization Tests #730
Enhance Documentation and Add Comprehensive Pluralization Tests #730
Conversation
…erent cases - English - Russian - Arabic
WalkthroughThe changes in this pull request involve the addition of a new section in the Changes
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (7)
test/easy_localization_plural_rules_unit_test.dart (5)
12-23
: Consider improving test setup clarity and error handlingA few suggestions to enhance the test setup:
- Consider adding a comment explaining the purpose of the 'fb' locale (fallback?)
- The error handler could include assertions or test failures for better error visibility
- The hardcoded 'path' value could be made more meaningful or documented
var r = EasyLocalizationController( - forceLocale: const Locale('fb'), + // 'fb' represents a fallback locale for testing + forceLocale: const Locale('fb'), supportedLocales: [const Locale('en'), const Locale('ar'), const Locale('ru'), const Locale('fb')], fallbackLocale: const Locale('fb'), - path: 'path', + path: 'test/fixtures', // Path to test translation files useOnlyLangCode: true, useFallbackTranslations: true, onLoadError: (FlutterError e) { - log(e.toString()); + log(e.toString()); + fail('Failed to load translations: ${e.toString()}'); }, saveLocale: false, assetLoader: const JsonAssetLoader());
29-74
: Consider adding edge cases to English pluralization testsThe English pluralization tests are comprehensive for positive integers, but consider adding:
- Tests for negative numbers
- Tests for decimal numbers
- Documentation explaining the behavioral differences between
ignorePluralRules=true/false
group('English plural', () { + // Tests behavior with decimal numbers + test('English decimal numbers (no ignorePluralRules)', () async { + Localization.load( + const Locale('en'), + translations: r.translations, + fallbackTranslations: r.fallbackTranslations, + ignorePluralRules: false, + ); + expect(Localization.instance.plural('hat', 1.5), 'other hats'); + expect(Localization.instance.plural('hat', 0.5), 'other hats'); + }); + + // Tests behavior with negative numbers + test('English negative numbers (no ignorePluralRules)', () async { + Localization.load( + const Locale('en'), + translations: r.translations, + fallbackTranslations: r.fallbackTranslations, + ignorePluralRules: false, + ); + expect(Localization.instance.plural('hat', -1), 'other hats'); + expect(Localization.instance.plural('hat', -2), 'other hats'); + });
76-127
: Add documentation explaining Russian plural rulesThe Russian pluralization tests are comprehensive but would benefit from documentation explaining the language-specific rules. Consider adding comments explaining:
- The rules for 'few' (2-4, 22-24, etc.)
- The rules for 'many' (5-20, 25-30, etc.)
- Special cases like numbers ending in 1 but not 11
group('Russian plural', () { + // Russian has complex plural rules: + // one: n mod 10 = 1 and n mod 100 != 11 + // few: n mod 10 = 2..4 and n mod 100 != 12..14 + // many: n mod 10 = 0 or n mod 10 = 5..9 or n mod 100 = 11..14 + // other: everything else + test('Russian one', () async {
129-192
: Add documentation for Arabic plural rules and verify issue #729 fixThe Arabic pluralization tests address the issue mentioned in #729, but would benefit from:
- Documentation explaining Arabic plural rules
- Comments linking these tests to issue Plural Support Missing 'Few' Case for Some Languages Like Arabic | Default Behavior of ignorePluralRules #729
- Additional test cases for boundary conditions
group("Arabic plural", () { + // Arabic plural rules: + // zero: n = 0 + // one: n = 1 + // two: n = 2 + // few: n mod 100 = 3..10 + // many: n mod 100 = 11..99 + // other: everything else + // + // Related to issue #729: Missing 'few' case for numbers <= 10 + test('Arabic few (no ignorePluralRules)', () async {
1-212
: Consider structuring tests for better maintainabilityWhile the tests are comprehensive, consider these architectural improvements:
- Extract test data into fixture files to separate test logic from test data
- Create shared setup functions for common locale configurations
- Add a test matrix to ensure consistent coverage across all locales
Would you like assistance in implementing any of these improvements?
README.md (2)
320-324
: Enhance the introduction with specific language examples.The introduction effectively explains the default behavior but could be more helpful by explicitly mentioning which languages require the
few
andmany
categories.Consider expanding the introduction like this:
-In some languages, pluralization is simple and only involves using zero, one, two, and other forms, without needing to handle the `few` or `many` categories. +In some languages like English, pluralization is simple and only involves using zero, one, two, and other forms. However, other languages like Arabic, Russian, and Polish require additional plural categories such as `few` or `many` for grammatically correct translations.
329-337
: Add a practical example demonstrating plural forms.While the configuration example is clear, it would be more helpful to include a practical example showing the actual plural forms in use.
Consider adding this example after the configuration:
EasyLocalization( ignorePluralRules: false, // Set this line to false to enable 'few' and 'many' plural categories supportedLocales: [Locale('en', 'US'), Locale('de', 'DE')], path: 'assets/translations', fallbackLocale: Locale('en', 'US'), child: MyApp() ) +// Example for Arabic pluralization with all forms: +{ + "items": { + "zero": "لا يوجد عناصر", + "one": "عنصر واحد", + "two": "عنصران", + "few": "{} عناصر", // For numbers 3-10 + "many": "{} عنصراً", // For numbers 11-99 + "other": "{} عنصر" // For everything else + } +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
README.md
(1 hunks)test/easy_localization_plural_rules_unit_test.dart
(1 hunks)
🔇 Additional comments (2)
README.md (2)
338-341
: LGTM! Clear explanation of the configuration impact.
The final explanation clearly states the effect of setting ignorePluralRules: false
.
320-341
: Documentation changes successfully address issue #729.
The new section effectively documents the solution to the missing 'few' plural case issue in Arabic and similar languages. The content is well-structured and provides clear guidance for users needing to handle additional plural categories.
✅ Verification successful
Documentation accurately reflects implementation and test coverage
The documentation changes are well-aligned with the codebase implementation, as evidenced by comprehensive test coverage across multiple test files. The tests verify:
- Proper handling of 'few' and 'many' plural cases when
ignorePluralRules: false
- Language-specific plural rules (including Russian and Arabic)
- Widget integration with plural rules
- Various numeric cases for different plural forms
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify if the documentation changes are reflected in tests
rg -l "ignorePluralRules.*false" "test/"
Length of output: 182
Script:
#!/bin/bash
# Check the test implementations to verify proper testing of ignorePluralRules
rg "ignorePluralRules.*false" test/ -B 2 -A 4
Length of output: 7055
test('Arabic all cases (with ignorePluralRules) | using `_pluralCaseFallback`', () async { | ||
Localization.load( | ||
const Locale('en'), | ||
translations: r.translations, | ||
fallbackTranslations: r.fallbackTranslations, | ||
ignorePluralRules: true, | ||
); | ||
|
||
expect(Localization.instance.plural('hat', 0), 'no hats'); | ||
expect(Localization.instance.plural('hat', 1), 'one hat'); | ||
expect(Localization.instance.plural('hat', 2), 'two hats'); | ||
expect(Localization.instance.plural('hat', 3), 'other hats'); | ||
expect(Localization.instance.plural('hat', 4), 'other hats'); | ||
expect(Localization.instance.plural('hat', 11), 'other hats'); | ||
expect(Localization.instance.plural('hat', 101), 'other hats'); | ||
expect(Localization.instance.plural('hat', 111), 'other hats'); | ||
expect(Localization.instance.plural('hat', 103), 'other hats'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect locale in Arabic test case
There appears to be a bug in the test setup. The test is titled "Arabic all cases" but uses the English locale ('en') instead of Arabic ('ar').
Localization.load(
- const Locale('en'),
+ const Locale('ar'),
translations: r.translations,
fallbackTranslations: r.fallbackTranslations,
ignorePluralRules: true,
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
test('Arabic all cases (with ignorePluralRules) | using `_pluralCaseFallback`', () async { | |
Localization.load( | |
const Locale('en'), | |
translations: r.translations, | |
fallbackTranslations: r.fallbackTranslations, | |
ignorePluralRules: true, | |
); | |
expect(Localization.instance.plural('hat', 0), 'no hats'); | |
expect(Localization.instance.plural('hat', 1), 'one hat'); | |
expect(Localization.instance.plural('hat', 2), 'two hats'); | |
expect(Localization.instance.plural('hat', 3), 'other hats'); | |
expect(Localization.instance.plural('hat', 4), 'other hats'); | |
expect(Localization.instance.plural('hat', 11), 'other hats'); | |
expect(Localization.instance.plural('hat', 101), 'other hats'); | |
expect(Localization.instance.plural('hat', 111), 'other hats'); | |
expect(Localization.instance.plural('hat', 103), 'other hats'); | |
}); | |
test('Arabic all cases (with ignorePluralRules) | using `_pluralCaseFallback`', () async { | |
Localization.load( | |
const Locale('ar'), | |
translations: r.translations, | |
fallbackTranslations: r.fallbackTranslations, | |
ignorePluralRules: true, | |
); | |
expect(Localization.instance.plural('hat', 0), 'no hats'); | |
expect(Localization.instance.plural('hat', 1), 'one hat'); | |
expect(Localization.instance.plural('hat', 2), 'two hats'); | |
expect(Localization.instance.plural('hat', 3), 'other hats'); | |
expect(Localization.instance.plural('hat', 4), 'other hats'); | |
expect(Localization.instance.plural('hat', 11), 'other hats'); | |
expect(Localization.instance.plural('hat', 101), 'other hats'); | |
expect(Localization.instance.plural('hat', 111), 'other hats'); | |
expect(Localization.instance.plural('hat', 103), 'other hats'); | |
}); |
…ules) | using `_pluralCaseFallback``
Thanks for the great PR @MAlazhariy |
Resolves #729
These updates enhance the clarity of the package's functionality and strengthen its reliability across multiple languages.
Summary by CodeRabbit
ignorePluralRules
flag.