Skip to content
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

test numeric value as input for issue #99 #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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