i18n fallback doesn't work for localized views #840

Closed
lighthouse-import opened this Issue May 16, 2011 · 16 comments

Comments

Projects
None yet
5 participants

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6411
Created by Ola Tuvesson - 2011-02-11 09:30:57 UTC

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 fr.yml is found.

Can I monkey patch this somehow?

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-02-12 05:54:57 UTC

Could someone at least confirm if this is the expected behaviour or not?

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-02-13 14:13:45 UTC

Hi Ola,

I have spoken to José about this issue and it does seem to be a bug when using I18n Fallbacks.

Thanks for reporting the issue, I will take a look at creating a patch for master this week.

Thanks,

Josh

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-02-13 16:11:17 UTC

Thanks Josh! I need this as I'm working on a site which is available in both France and Canada, as well as in French language in other countries. So I en up with lots of language-country combinations; fr-FR, fr-CA, fr-CH, fr-UK - I really don't want to have separate help files for all of them!

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-02-17 12:51:39 UTC

While waiting for this to be patched, does anyone have any suggestions how I might implement a temporary fix for this? I need to do a new release of my project within the next day or so and this has to include the help pages.

Imported from Lighthouse.
Comment by Josh Kalderimis - 2011-02-17 12:57:38 UTC

Hey Ola,

Sorry for the delay, http://travis-ci.org is eating up my time. I have one patch I need to attend to first, then this one.

The temp fix could be to check if the file exists and render it if it does, otherwise strip off the country portion. This is a hack and ugly controller code, but it should work.

Thanks,

Josh

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-02-18 09:22:25 UTC

Thanks, that makes sense. But I was wondering which method it is I need to override? I've been digging around in the ActionView source, PathResolver and other places but I can't seem to locate the relevant locale based view lookup - though admittedly I'm not very well traveled in the Rails source. Could you drop me a hint?

Cheers,

Ola

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-02-18 10:23:21 UTC

For example, putting this in an initializer does not give me the German help view:

module ActionView
class LookupContex
module Details
def locale
:de
end
end
end
end

Imported from Lighthouse.
Comment by Ola Tuvesson - 2011-03-03 17:13:39 UTC

Any thoughts on this, anyone?

Contributor

tute commented Sep 10, 2012

Should this issue be reopened? I still see it in Rails 3.2.8.

Member

steveklabnik commented Sep 10, 2012

If you're seeing it, then yes.

steveklabnik reopened this Sep 10, 2012

Member

steveklabnik commented Nov 29, 2012

Applying the monkeypatch from #3512, I get these two unrelated failures:

  1) Failure:
test_render_file_with_dashed_locale(CachedViewRenderTest) [/Users/steve/src/rails/actionpack/test/template/render_test.rb:117]:
Expected: "Ola mundo"
  Actual: "Hello world!"

  2) Failure:
test_render_file_with_dashed_locale(LazyViewRenderTest) [/Users/steve/src/rails/actionpack/test/template/render_test.rb:117]:
Expected: "Ola mundo"
  Actual: "Hello world!"

So, that won't work as a simple fix.

Member

steveklabnik commented Nov 29, 2012

Right. Because we can render things like, for example, hello_world.pt-BR.html.erb. So we need a slightly more intelligent fix.

salzig commented Feb 28, 2013

I'm not quite sure, but is this problem maybe related to action_view/lookup_context.rb:203 where it returns just the first key instead of an array?

as far as i understand it, if locale would return an Array, the find method would try to find the first match and if locale would return I18n.fallbacks[I18n.locale] we had our solution?

edit: would be cool to hear some thoughts from @josevalim, cause he should have the best understanding of latest changes.

Contributor

imanel commented Mar 14, 2013

This should be fixed by #7368

Member

steveklabnik commented Mar 14, 2013

I just merged #7368 , so hopefully that fixes it? Can someone test it out?

Member

steveklabnik commented Apr 11, 2013

I'm going to assume that #7368 fixes this until further notice. Let me know if it doesn't.

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