Skip to content

Commit

Permalink
Merge pull request #72 from faberNovel/feature/skip_empty_strings_and…
Browse files Browse the repository at this point in the history
…roid

Do not export empty translation on Android
  • Loading branch information
ferrandp authored Mar 2, 2022
2 parents 14017b0 + bcdaa83 commit 76b6209
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/ad_localize/entities/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def ==(o)
o.value == value &&
o.comment == comment
end

def has_value?
value.present?
end
end
end
end
6 changes: 4 additions & 2 deletions lib/ad_localize/serializers/strings_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ def hash_binding(locale_wording:)
end

def map_singulars(translations:)
translations.map { |translation| @translation_mapper.map(translation: translation) }
translations.select(&:has_value?).map { |translation| @translation_mapper.map(translation: translation) }
end

def map_plurals(plurals:)
plurals.map { |label, translations| @translation_group_mapper.map(label: label, translations: translations) }
plurals
.map { |label, translations| @translation_group_mapper.map(label: label, translations: translations.select(&:has_value?)) }
.select(&:has_translations?)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/ad_localize/view_models/translation_group_view_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?(&:has_value?)
end
end
end
end
4 changes: 4 additions & 0 deletions lib/ad_localize/view_models/translation_view_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(label:, key:, value:, comment:)
@value = value
@comment = comment
end

def has_value?
value.present?
end
end
end
end

0 comments on commit 76b6209

Please sign in to comment.