Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Custom transliterations aren't take into account (ASCII-8BIT encoded keys?) #623

Closed
beauraF opened this issue Feb 14, 2022 · 3 comments

Comments

@beauraF
Copy link

beauraF commented Feb 14, 2022

Hello 👋

We are using custom rules for transliteration. Since #587 they are not taking into account anymore.
It seems that this is due to the fact that symbolize_names returns keys with ASCII-8BIT encoding :

> YAML.unsafe_load_file('config/locales/en.yml', symbolize_names: false, freeze: true)
=> {"en"=>{"i18n"=>{"transliterate"=>{"rule"=>{"ö"=>"oe"}}}}}

> YAML.unsafe_load_file('config/locales/en.yml', symbolize_names: true, freeze: true)
=> {:en=>{:i18n=>{:transliterate=>{:rule=>{:"\xC3\xB6"=>"oe"}}}}}

This is what @approximations contains in our HashTransliterator:

{"À"=>"A", ..., "ö"=>"o", ..., "\xC3\xB6"=>"oe" }

What I tried to do

en:
  i18n:
    transliterate:
      rule:
        ö: oe
 > I18n.transliterate('ö', locale: :en)

What I expected to happen

 > I18n.transliterate('ö', locale: :en)
=> "oe"

What actually happened

 > I18n.transliterate('ö', locale: :en)
=> "o"

Versions of i18n, rails, and anything else you think is necessary

  • Rails 7.0.2.2
  • Ruby 3.0.3
  • I18n 1.9.1
@lorenzk
Copy link

lorenzk commented Feb 14, 2022

Hi!

Are you by any chance using bootsnap? I have a very similar issue, albeit without using custom transliterations (only rails-i18n). It seems updating i18n from 1.8.11 to 1.9.1 while using bootsnap broke something:

assert_equal({  => "ae",  => "e",  => "ue",  => "oe",  => "Ae",  => "Ue",  => "Oe",  => "ss" }, I18n.t("i18n.transliterate.rule", locale: :de))

OK for 1.8.11 without bootsnap
OK for 1.8.11 with bootsnap
OK for 1.9.1 without bootsnap
Breaks for 1.9.1 with bootsnap:

Failure:
ApplicationHelperTest#test_all_countries_:de [/private/tmp/transliterate-bug/test/helpers/application_helper_test.rb:5]:
--- expected
+++ actual
@@ -1 +1 @@
-{:ä=>"ae", :é=>"e", :ü=>"ue", :ö=>"oe", :Ä=>"Ae", :Ü=>"Ue", :Ö=>"Oe", :ß=>"ss"}
+{:"\xC3\xA4"=>"ae", :"\xC3\xA9"=>"e", :"\xC3\xBC"=>"ue", :"\xC3\xB6"=>"oe", :"\xC3\x84"=>"Ae", :"\xC3\x9C"=>"Ue", :"\xC3\x96"=>"Oe", :"\xC3\x9F"=>"ss"}

I made a demo repository with a rails new --minimal, a single test file and branches for each combination of i18n version and bootsnap enabled/disabled:

https://github.com/lorenzk/i18n-transliterate-bug/pulls

Versions of i18n, rails, and anything else you think is necessary

  • Rails 7.0.2.2
  • Ruby 3.1.0
  • I18n 1.9.1 and 1.8.11

@lorenzk
Copy link

lorenzk commented Feb 14, 2022

Sorry, I just realized that my problem is a duplicate of #606

@beauraF
Copy link
Author

beauraF commented Feb 14, 2022

Oh, it seems mine too. I missed it. Thanks @lorenzk for pointing it out. :)

@beauraF beauraF closed this as completed Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants