Skip to content

Commit

Permalink
Merge pull request #362 from romuloceccon/transliterate_non_ascii
Browse files Browse the repository at this point in the history
Fix transliteration to default replacement char
  • Loading branch information
radar committed Feb 22, 2017
2 parents 529d61c + 6b60a5b commit 96f6e70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/i18n/backend/transliterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def initialize(rule = nil)
add rule if rule
end

def transliterate(string, replacement = DEFAULT_REPLACEMENT_CHAR)
def transliterate(string, replacement = nil)
replacement ||= DEFAULT_REPLACEMENT_CHAR
string.gsub(/[^\x00-\x7f]/u) do |char|
approximations[char] || replacement
end
Expand Down
4 changes: 4 additions & 0 deletions test/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ def call(exception, locale, key, options); key; end
end
end

test "transliterate non-ASCII chars not in map with default replacement char" do
assert_equal "???", I18n.transliterate("日本語")
end

test "I18n.locale_available? returns true when the passed locale is available" do
I18n.available_locales = [:en, :de]
assert_equal true, I18n.locale_available?(:de)
Expand Down

0 comments on commit 96f6e70

Please sign in to comment.