diff options
author | Kaan Ozkan <kaan.ozkan@shopify.com> | 2019-03-11 11:44:28 -0400 |
---|---|---|
committer | Kaan Ozkan <kaan.ozkan@shopify.com> | 2019-03-11 11:47:31 -0400 |
commit | bc9711fb7d6dd89094ccc9c8f3147bcf3ddd63bc (patch) | |
tree | 967ab886109c6b2fdbb2ed0c61b5ae1e59da6f9d /activesupport/lib/active_support/core_ext | |
parent | 4304373788fda6fa0fb1d6bac4ef78fb1ecac3dd (diff) | |
download | rails-bc9711fb7d6dd89094ccc9c8f3147bcf3ddd63bc.tar.gz rails-bc9711fb7d6dd89094ccc9c8f3147bcf3ddd63bc.tar.bz2 rails-bc9711fb7d6dd89094ccc9c8f3147bcf3ddd63bc.zip |
Add locale option to parameterize
Parameterize is triggering I18n#transliterate. This method already
accepts a locale. It would be cleaner if similar to other string inflection
methods #parameterize also accepted 'locale' as a parameter.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/inflections.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 8af301734a..e63b38b227 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -162,6 +162,11 @@ class String # Replaces special characters in a string so that it may be used as part of a 'pretty' URL. # + # If the optional parameter +locale+ is specified, + # the word will be parameterized as a word of that language. + # By default, this parameter is set to <tt>nil</tt> and it will use + # configured I18n.locale + # # class Person # def to_param # "#{id}-#{name.parameterize}" @@ -187,8 +192,8 @@ class String # # <%= link_to(@person.name, person_path) %> # # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a> - def parameterize(separator: "-", preserve_case: false) - ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case) + def parameterize(separator: "-", preserve_case: false, locale: nil) + ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case, locale: locale) end # Creates the name of a table like Rails does for models to table names. This method |