-
Notifications
You must be signed in to change notification settings - Fork 8
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
Do not export empty translation on Android #72
Conversation
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.
With a method has_value?
in the Translation entity and another one has_translations?
in TranslationGroupViewModel you can refactor the code like this :
# translation.rb
def has_value?
value.present?
end
# translation_group_view_model.rb
def has_translations?
translation_view_models.present?
end
# strings_serializer.rb
def map_singulars(translations:)
translations.select(&:has_value?).map { |translation| @translation_mapper.map(translation: translation) }
end
def map_plurals(plurals:)
plurals
.select(&:has_value?)
.map { |label, translations| @translation_group_mapper.map(label: label, translations: translations) }
.select(&:has_translations?)
end
Otherwise you can also write it like this
def map_singulars(translations:)
translations
.select { |translation| translation.value.present? }
.map { |translation| @translation_mapper.map(translation: translation) }
end
def map_plurals(plurals:)
plurals
.select { |translation| translation.value.present? }
.map { |label, translations| @translation_group_mapper.map(label: label, translations: translations) }
.select { |translation| translation.translation_view_models.present? }
end
@@ -10,6 +10,10 @@ def initialize(label:, translation_view_models:) | |||
@label = label | |||
@translation_view_models = translation_view_models | |||
end | |||
|
|||
def has_translations? | |||
(translation_view_models || []).any? { |translation| translation.value.present? } |
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.
Just one more change : .any? { |translation| translation.value.present? }
=> .any?(&:has_value?)
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.
Those are translation ViewModels, not translations so they have no has_value
method. I did not know if it makes sense to add such a method for a ViewModel. What do you think ?
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.
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.
One more change and we are good
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.
Thank you for this PR
Android can handle when a translation is missing, but if the translation is empty Android will display an empty string, which is not what we want.