Skip to content

Commit

Permalink
test numeric value as input for issue glebm#99
Browse files Browse the repository at this point in the history
  • Loading branch information
rngadam committed Oct 10, 2014
1 parent c43cd5c commit 1104bab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/i18n/tasks/google_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def dump_value(value)
value.map { |v| dump_value v }
when String
replace_interpolations value
when Fixnum
value.to_s
else
value
end
Expand All @@ -74,13 +76,17 @@ def parse_value(untranslated, each_translated)
restore_interpolations untranslated, each_translated.next
when NilClass
nil
when Fixnum
untranslated
else
each_translated.next
end
end

INTERPOLATION_KEY_RE = /%\{[^}]+\}/.freeze
UNTRANSLATABLE_STRING = 'zxzxzx'.freeze
OBJECT_STRING = 'zyzyzy'.freeze
OBJECT_STRING_REGEXP = /^zyzyzy/

# 'hello, %{name}' => 'hello, <round-trippable string>'
def replace_interpolations(value)
Expand Down
5 changes: 4 additions & 1 deletion spec/google_translate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
include I18n::Tasks::GoogleTranslation

tests = [
numeric_value_test = ['numeric-key', 1, 1],
nil_value_test = ['nil-value-key', nil, nil],
text_test = ['key', "Hello - %{user} O'neill!", "Hola - %{user} O'neill!"],
html_test = ['html-key.html', "Hello - <b>%{user} O'neill</b>", "Hola - <b>%{user} O'neill</b>"],
Expand Down Expand Up @@ -45,7 +46,8 @@
'hello' => text_test[1],
'hello_html' => html_test[1],
'array_key' => array_test[1],
'nil-value-key' => nil_value_test[1]
'nil-value-key' => nil_value_test[1],
'numeric-key' => numeric_value_test[1]
}
})
task.data[:es] = build_tree('es' => {
Expand All @@ -59,6 +61,7 @@
expect(task.t('common.hello_html', 'es')).to eq(html_test[2])
expect(task.t('common.array_key', 'es')).to eq(array_test[2])
expect(task.t('nil-value-key', 'es')).to eq(nil_value_test[2])
expect(task.t('common.numeric-key', 'es')).to eq(numeric_value_test[2])
expect(task.t('common.a', 'es')).to eq('λ')
end
end
Expand Down

0 comments on commit 1104bab

Please sign in to comment.