i18n locale fallback for localized views #3512

Closed
clickworkorange opened this Issue Nov 4, 2011 · 6 comments

Comments

Projects
None yet
3 participants

Given that I have set i18n to fall back (e.g. from "fr-Fr" to just "fr"):

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

And I have created a localized view (e.g. /help/index.fr.html.erb)

When i18n locale is set to "fr-FR", then the localized view is not found - yet the language file config/locales/fr.yml is found.

This issue was raised previously (#840) and confirmed as a bug, but I just noticed it is still broken in 3.0.9 - and the previous issue has been automatically closed. One of the gems that my app depends on is not compatible with 3.1 so I haven't been able to test if this issue has been resolved there. Any input much appreciated!

For the time being I'm overriding the ActionView LookupContext locale method to only use the first two characters of the locale string. Like so:

module ActionView
  class LookupContext
    module Details
      def locale=(value)
        if value
          config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
          config.locale = value[0,2] # only use first part of the locale in lookups
        end
        super(@skip_default_locale ? I18n.locale : _locale_defaults)
      end
    end
  end
end
Member

steveklabnik commented Apr 29, 2012

Hey @mikrogroove: is this still an issue in 3.2? If you can't test it, let me know and I'll give it a go.

Hi @steveklabnik! Yes, it appears the issue remains the same in 3.2; lookups try to find (for example) "fr-FR" and fail to locate the "fr" views. I had to update my LookupContext initializer since the setter for locale has been moved out of the "Details" module (it appears this module has been refactored out altogether), but I can confirm that I still need to force the lookup to only use the first two characters in the locale for my views to be found. In module ActionView, class LookupContext, method locale=(value):

config.locale = value # Fails to find index.fr.html.erb when locale is fr-FR

config.locale = value[0,2] # Works

Member

steveklabnik commented Apr 30, 2012

Awesome, thanks for confirming. Trying to make sure that older issues are still important.

Not awesome that it's still a bug though.

Member

senny commented Oct 13, 2012

as mentioned in the ticket header this is a duplicate of #840.

@steveklabnik I think we should close one of them to focus the discussion on a single issue.

Member

steveklabnik commented Oct 13, 2012

Yes, since #840 is open, I'm gonna close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment