Skip to content

Commit

Permalink
Possible fix for #99
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Oct 10, 2014
1 parent c43cd5c commit b92a42b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/i18n/tasks/google_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def validate_google_translate_api_key!(key)
end

def to_values(list)
list.map { |l| dump_value l[1] }.flatten.compact
list.flat_map { |l| dump_value l[1] }.compact
end

def from_values(list, translated_values)
Expand All @@ -53,6 +53,8 @@ def from_values(list, translated_values)
keys.zip parse_value(untranslated_values, translated_values.to_enum)
end

# Prepare value for translation
# Only translate String and Array<String>
def dump_value(value)
case value
when Array
Expand All @@ -61,21 +63,22 @@ def dump_value(value)
when String
replace_interpolations value
else
value
nil
end
end

# Parse translated value from the each_translated enumerator
# @param [Array] untranslated
# @param [Enumerator] each_translated
def parse_value(untranslated, each_translated)
case untranslated
when Array
# implode array
untranslated.map { |from| parse_value(from, each_translated) }
when String
restore_interpolations untranslated, each_translated.next
when NilClass
nil
else
each_translated.next
untranslated
end
end

Expand Down

0 comments on commit b92a42b

Please sign in to comment.