Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@hurali97 I believe the correct way to fix this bug is to return the result of the translation as it is, similar to what was previously done: Here is a simple code diff, please give me your thoughts:
code
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.
Actually, I think we should refactor the code in
getTranslatedPhrase
, Previously we were checking the existence of a key inside the Translations object, but now we check the value of the translation which doesn't look correct IMO.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.
cc @hurali97 Here is my latest attempt to address the concerns raised in the previous comment: I believe we should refactor the
getTranslatedPhrase
code and introduce a new flagisValidKey
in its response. This way, the function should return both the value and the validity of the key. Here is the updated code:Code
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.
@fedirjh Your latest code looks nice and I have incorporated it with just renaming the type name from
CacheValue
toTranslatedValue
. Is that fine with you?If we did that we will have the same bug where we show the translation key in UI for the value which is an empty string. To fill you in, previously we were checking for Truthiness of
translatedPhrase
and if it's an empty string, which can happen because of variables, we will have an empty string astranslatedPhrase
, which is what is expected. So in such cases, returningphraseKey
instead would be a violation.But I guess it's also fixed by your latest code, so that's fine 👍
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.
Yes, we are in agreement. By "the result of the translation as it is" I meant the value, even if it's empty or null, not the 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.
I actually think that the code was simpler and just as clear before - strings (including empty strings) are valid results, but
null
orundefined
are not.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.
i.e: if the translation isn't found,
getTranslatedPhrase
should just returnnull
, rather than{value: '', isValidKey: false}
. If the translation is found and happens to be an empty string, that's fineThere 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.
@roryabraham Yes, but this won't tell us if the key exists or not. with previous code ,
null
orundefined
means that it's either :null
orundefined
. this can happen if we have a function maybe?In the second case, In staging or production it will log an alert to the server about a key not found, which is not what we want?