-
-
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
[fix] Small fix on Translations.get #564
base: develop
Are you sure you want to change the base?
Conversation
@DrBu7cher Thanks for this PR, a very good idea! Maybe we should add a dedicated warning-log in this case, so the user knows what's wrong? Anyways, it would be important to have a unittest covering this, so it's not destroyed by a another change. |
@@ -13,7 +13,8 @@ class Translations { | |||
|
|||
/// If we failed to find the key as a nested key, then fall back | |||
/// to looking it up like normal. | |||
returnValue ??= _translations?[key]; | |||
var maybeValue = _translations?[key]; |
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.
Now we do the lookup all the time, even if it's not needed because returnValue != null
@@ -13,7 +13,8 @@ class Translations { | |||
|
|||
/// If we failed to find the key as a nested key, then fall back | |||
/// to looking it up like normal. | |||
returnValue ??= _translations?[key]; | |||
var maybeValue = _translations?[key]; | |||
if (maybeValue is String) returnValue ??= maybeValue; |
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.
we need a unittest for the new behavior
2cf1f0e
to
041eebe
Compare
041eebe
to
bcf8f05
Compare
Good ideas, I will come back to that. |
I got an error like this:
from
Translations.get
.I had a JSON for translation like
etc.
My code was trying to translate like
tr(errorString)
whereerrorString
was"error"
and this led to the lookup in lib/src/translations.dart#L16 to try and put the resulting Map () into a String?.
This PR fixes the problem and just gives
[🌎 Easy Localization] [WARNING] Localization key [error] not found
as expected.I did not check in any other places, if this could happen. If an error occurs somewhere else, I will open a new PR.
By the way, when will you release the next time? The last release on pub.dev was 10 months ago...?