mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix bug with parametrize when locale
is passed
Also add tests for parametrize and transliterate
This commit is contained in:
parent
878e98091d
commit
818437c366
4 changed files with 19 additions and 1 deletions
|
@ -90,7 +90,7 @@ module ActiveSupport
|
||||||
#
|
#
|
||||||
def parameterize(string, separator: "-", preserve_case: false, locale: nil)
|
def parameterize(string, separator: "-", preserve_case: false, locale: nil)
|
||||||
# Replace accented chars with their ASCII equivalents.
|
# Replace accented chars with their ASCII equivalents.
|
||||||
parameterized_string = transliterate(string, locale)
|
parameterized_string = transliterate(string, locale: locale)
|
||||||
|
|
||||||
# Turn unwanted chars into the separator.
|
# Turn unwanted chars into the separator.
|
||||||
parameterized_string.gsub!(/[^a-z0-9\-_]+/i, separator)
|
parameterized_string.gsub!(/[^a-z0-9\-_]+/i, separator)
|
||||||
|
|
|
@ -206,6 +206,12 @@ class StringInflectionsTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parameterize_with_locale
|
||||||
|
word = "Fünf autos"
|
||||||
|
I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })
|
||||||
|
assert_equal("fuenf-autos", word.parameterize(locale: :de))
|
||||||
|
end
|
||||||
|
|
||||||
def test_humanize
|
def test_humanize
|
||||||
UnderscoreToHuman.each do |underscore, human|
|
UnderscoreToHuman.each do |underscore, human|
|
||||||
assert_equal(human, underscore.humanize)
|
assert_equal(human, underscore.humanize)
|
||||||
|
|
|
@ -304,6 +304,12 @@ class InflectorTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parameterize_with_locale
|
||||||
|
word = "Fünf autos"
|
||||||
|
I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })
|
||||||
|
assert_equal("fuenf-autos", ActiveSupport::Inflector.parameterize(word, locale: :de))
|
||||||
|
end
|
||||||
|
|
||||||
def test_classify
|
def test_classify
|
||||||
ClassNameToTableName.each do |class_name, table_name|
|
ClassNameToTableName.each do |class_name, table_name|
|
||||||
assert_equal(class_name, ActiveSupport::Inflector.classify(table_name))
|
assert_equal(class_name, ActiveSupport::Inflector.classify(table_name))
|
||||||
|
|
|
@ -30,6 +30,12 @@ class TransliterateTest < ActiveSupport::TestCase
|
||||||
I18n.locale = default_locale
|
I18n.locale = default_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_transliterate_respects_the_locale_argument
|
||||||
|
char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS
|
||||||
|
I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })
|
||||||
|
assert_equal "ue", ActiveSupport::Inflector.transliterate(char, locale: :de)
|
||||||
|
end
|
||||||
|
|
||||||
def test_transliterate_should_allow_a_custom_replacement_char
|
def test_transliterate_should_allow_a_custom_replacement_char
|
||||||
assert_equal "a*b", ActiveSupport::Inflector.transliterate("a索b", "*")
|
assert_equal "a*b", ActiveSupport::Inflector.transliterate("a索b", "*")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue