How do you set up transliteration in a Rails 3 application?

Ultimately, I would like to use Inflector.parameterize to create spoils for the title of an article that has a bunch of unicode characters (for example, "ḤellẒ no" => "hellz-no"). According to http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate , he says to put them in the locales / en.yml file.

# Store the transliterations in locales/en.yml i18n: transliterate: rule: Ḥ: "h" Ẓ: "z" 

I tried this, but the following does not work:

 "ḤellẒ no".parameterize # => "ell-no" 

However, when I change it in Ruby, as the second paragraph suggests, it works.

 I18n.backend.store_translations(:en, :i18n => { :transliterate => { :rule => { "Ḥ" => "H", "Ẓ" => "Z" } } }) "ḤellẒ no".parameterize # => "hellz-no" 

I suppose I would like to know why putting user transliterations in locales / en.yml does not work.

And even if someone gives an answer for this, being a Rails noob, I would also like to know where the code similar to the second block is usually put to set I18n.backend.store_translations manually?

+2
source share
2 answers

Eh, I have a part of the answer. Unlike the da document http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-transliterate , yml files must indicate the language - i.e. de:

 # Store the transliterations in locales/de.yml de: i18n: transliterate: rule: ü: "ue" ö: "oe" 

Please answer the second part of the question, where should the code I18n.backend.store_translations (: en, ... live in the Rails 3 application look like?

+5
source

[...] where should the code I18n.backend.store_translations (: en, ... live in the Rails 3 application look like?

I know. I could be a little late for this, but I would put it in the initialization file: config/initializers/i18n.rb

+1
source

Source: https://habr.com/ru/post/899630/


All Articles