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

[QUESTION] Resolve Symbols based on original fallback locale? #590

Closed
movermeyer opened this issue Dec 15, 2021 · 0 comments · Fixed by #591
Closed

[QUESTION] Resolve Symbols based on original fallback locale? #590

movermeyer opened this issue Dec 15, 2021 · 0 comments · Fixed by #591

Comments

@movermeyer
Copy link
Contributor

movermeyer commented Dec 15, 2021

When trying to integrate CLDR data provided by ruby-i18n/ruby-cldr, the interaction between symbols and the Fallbacks backend is not quite what I'm hoping for.

CLDR defines "aliases" that indicate that a lookup should restart at a different key than the key currently being looked up. i18n allows for a similar thing by "resolving" Symbols that it finds.

However, CLDR aliases restart the lookup from the original locale, while i18n restarts the lookup from the locale that it found the alias in.

I'm wondering if there is a way to support CLDR aliases in i18n?
Aside: I'm the new maintainer of ruby-cldr 👋, so we can make changes on that end if needed.


I18n config:

I18n::Backend::Simple.include(
  I18n::Backend::Fallbacks,
  I18n::Backend::Pluralization,
)

I18n.enforce_available_locales = false

I18n.fallbacks = I18n::Locale::Fallbacks.new(:root) # Overly simple fallback implementation for demonstration
I18n.load_path += Dir[File.join("data/**/*.yml")]

data/ak/calendars.yml:

---
ak:
  calendars:
    gregorian:
      months:
        format:
          abbreviated:
            1: S-Ɔ
            2: K-Ɔ
            3: E-Ɔ
            4: E-O
            5: E-K
            6: O-A
            7: A-K
            8: D-Ɔ
            9: F-Ɛ
            10: Ɔ-A
            11: Ɔ-O
            12: M-Ɔ

data/root/calendars.yml:

---
root:
  calendars:
    gregorian:
      months:
        format:
          abbreviated: :calendars.gregorian.months.format.wide
          wide:
            1: M01
            2: M02
            3: M03
            4: M04
            5: M05
            6: M06
            7: M07
            8: M08
            9: M09
            10: M10
            11: M11
            12: M12
        stand-alone:
          abbreviated: :calendars.gregorian.months.format.abbreviated
I18n.fallbacks[:ak]
# => [:ak, :root]

I18n.with_locale(:ak) do
  I18n.t("calendars.gregorian.months.stand-alone.abbreviated")
end
# => {1=>"M01", 2=>"M02", 3=>"M03", 4=>"M04", 5=>"M05", 6=>"M06", 7=>"M07", 8=>"M08", 9=>"M09", 10=>"M10", 11=>"M11", 12=>"M12"}

The lookup fails in ak, and falls back to root. When a symbol is found, it resolves that symbol, by starting a new lookup.
However, that lookup doesn't restart at ak, but at root. The result is that it finds root's :calendars.gregorian.months.format.abbreviated instead of ak's.

Desired: Entries from ak's :calendars.gregorian.months.format.abbreviated via root's calendars.gregorian.months.stand-alone.abbreviated

Received: Entries from root's :calendars.gregorian.months.format.wide via root's :calendars.gregorian.months.format.abbreviated via root's calendars.gregorian.months.stand-alone.abbreviated

Run this example

Runnable code can be found here: https://github.com/movermeyer/i18n_test/tree/movermeyer/fallbacks_with_symbols

git clone https://github.com/movermeyer/i18n_test.git
cd i18n_test
git checkout movermeyer/fallbacks_with_symbols
bundle install
ruby test_fallbacks_with_symbols.rb

Potential solution?

IDK yet. I threw together a "proof-of-concept" PR here.

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

Successfully merging a pull request may close this issue.

1 participant