Domanda

So, I wanted to pre-load the transliteration rules for many locales I have. I've included the following code in one of my initializers files (app/config/initializers/locales.rb):

I18n.backend.store_translations(:en, :i18n => {
:transliterate => {
    :rule => {
        "а" => "a",
        "б" => "b"
    }
}
})

But, if i try to make a transliteration: I18n.transliterate("Some Russian text"), I receive bunch of "?" signs, meaning that the transliterator doesn't have rules, so he doesn't know how to make a transliteration.

BUT!

If I have them (rules) defined in locales file (en.yml) like this:

en:
  i18n:
    transliterate:
      rule:
        а: "а"
        б: "b"

Then it works - Although I have a question, regarding HOW it works. If I specify I18n.transliterate("абвгд") - works good, but If I do "абвгд".parameterize, for some pescy reason, the letter "a" is being ommited (Like if there was no "a" letter in the first place).

WHY ?

Can someone help ?

È stato utile?

Soluzione

Looks like you have got a cyrillic 'а' (char code 1072) mapped to a cyrillic 'а' in your en.yml. Do you just need to map cyrillic 'а' to roman 'a'?

en:
  i18n:
    transliterate:
      rule:
        а: "a"
        б: "b"

(both seem to look the same on this site I think).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top