[QUESTION] Resolve `Symbols` based on original fallback locale?
movermeyer opened this issue · 0 comments
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" Symbol
s 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.