-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
Align trExists API with tr/plural #738
Conversation
WalkthroughThe changes enhance the localization functionality in the Easy Localization library by introducing an optional Changes
Sequence DiagramsequenceDiagram
participant Client
participant trExists
participant Localization
alt With Context
Client->>trExists: key, context
trExists->>Localization: of(context)
Localization-->>trExists: localization instance
trExists->>trExists: Check key existence
else Without Context
Client->>trExists: key
trExists->>Localization: Use global instance
trExists->>trExists: Check key existence
end
trExists-->>Client: Boolean result
Poem
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: 0
🧹 Nitpick comments (1)
test/easy_localization_test.dart (1)
719-722
: Add test coverage for context parameter scenarios.While the current tests cover the basic functionality, consider adding test cases for:
- Testing with a valid BuildContext
- Testing with null context
- Testing with an invalid context (should throw LocalizationNotFoundException)
Here's a suggested implementation:
test('trExists with context', () { final mockContext = MockBuildContext(); expect(trExists('test', context: mockContext), true); expect(trExists('xyz', context: mockContext), false); }); test('trExists with null context', () { expect(trExists('test', context: null), true); expect(trExists('xyz', context: null), false); }); test('trExists with invalid context', () { final invalidContext = MockBuildContext(); expect( () => trExists('test', context: invalidContext), throwsA(isA<LocalizationNotFoundException>()), ); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/src/public.dart
(1 hunks)lib/src/public_ext.dart
(2 hunks)test/easy_localization_test.dart
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
lib/src/public.dart (1)
48-53
: LGTM! Implementation aligns with existing patterns.The implementation correctly follows the established pattern used in
tr()
andplural()
functions for context handling.lib/src/public_ext.dart (2)
93-93
: LGTM! String extension implementation is correct.The implementation properly forwards the context parameter to the core implementation.
222-230
: LGTM! BuildContext extension implementation is correct.The implementation properly handles the localization not found case and follows the established pattern.
Thanks for the contribution @omj-denis |
Thanks for this useful library!
This PR adds some missing parts for
trExists
function:trExists
should acceptcontext
as an argument (similar totr
andplural
API)trExists
was available as a standalone function and as aString
extension previously. This PR also extendsBuildContext
with it (similar totr
andplural
).Without a context,
trExists
function would have an issue similar to #448 and #552.Summary by CodeRabbit
New Features
trExists
methodTests
The changes provide more flexible localization support, allowing developers to check translation key existence with or without a specific context.