MailingList


rendering localized templates

View: New views
3 Messages — Rating Filter:   Alert me  

rendering localized templates

by Duco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'have been looking through the FAQ's and this mailing list's archive. Although I did found some messages related to this, I did not found a way to get localized templates to work.

In my application, there is a template called "howto.rhtml". According the documentation, I create a template "howto.nl-NL.rhtml" and set the locale to "nl-NL". While all my view translations in other places in the applications do work and are nicely translated in Dutch, I never get "howto.nl-NL.rhtml", which is currently rendered from a trivial action in a controller:

def howto
end

I took a look in the source code of Globalize and I think the "magic" is in lib/globalize/rails/action_view.rb (method render_file). But the logic of selecting a "version" of <template>.rhtml, such as <template>.nl-NL.rhtml does not seem the called. When I trigger a stack trace during the rendering of howto.rhtml, I don't see any Globalize-specific methods in the call stack (just standard RoR methods).

I did try to make the controller method more explicit in what template to render:


def howto
  render :action, 'howto'
end

but this does not make any  change.

The only way I found to do anything with howto.nl-NL.rhtml is by calling

render :file, 'howto.rhtml'

which indeed renders howto.nl-NL.rhtml when the locale is set to nl-NL. But this renders the template as plain text, not as HTML. Including a component 'text.html' in the file name, as seems to be suggested by some other messages in this mailing list, does not make any difference here (but maybe this works for ActionMailer only, not for ActionView?).

Any ideas how to make localized templates work? (I'm using RoR 1.2.6 and a recent version of the for-1.2 of Globalize.

Thanks,

Duco



Re: rendering localized templates

by Joshua Wehner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try 'howto.nl.rhtml', that has worked for me in the past.


-- joshua

On Tue, Mar 4, 2008 at 10:02 AM, Duco <duco@...> wrote:

>
>  I'have been looking through the FAQ's and this mailing list's archive.
>  Although I did found some messages related to this, I did not found a way to
>  get localized templates to work.
>
>  In my application, there is a template called "howto.rhtml". According the
>  documentation, I create a template "howto.nl-NL.rhtml" and set the locale to
>  "nl-NL". While all my view translations in other places in the applications
>  do work and are nicely translated in Dutch, I never get "howto.nl-NL.rhtml",
>  which is currently rendered from a trivial action in a controller:
>
>  def howto
>  end
>
>  I took a look in the source code of Globalize and I think the "magic" is in
>  lib/globalize/rails/action_view.rb (method render_file). But the logic of
>  selecting a "version" of <template>.rhtml, such as <template>.nl-NL.rhtml
>  does not seem the called. When I trigger a stack trace during the rendering
>  of howto.rhtml, I don't see any Globalize-specific methods in the call stack
>  (just standard RoR methods).
>
>  I did try to make the controller method more explicit in what template to
>  render:
>
>
>  def howto
>   render :action, 'howto'
>  end
>
>  but this does not make any  change.
>
>  The only way I found to do anything with howto.nl-NL.rhtml is by calling
>
>  render :file, 'howto.rhtml'
>
>  which indeed renders howto.nl-NL.rhtml when the locale is set to nl-NL. But
>  this renders the template as plain text, not as HTML. Including a component
>  'text.html' in the file name, as seems to be suggested by some other
>  messages in this mailing list, does not make any difference here (but maybe
>  this works for ActionMailer only, not for ActionView?).
>
>  Any ideas how to make localized templates work? (I'm using RoR 1.2.6 and a
>  recent version of the for-1.2 of Globalize.
>
>  Thanks,
>
>  Duco
>

Re: rendering localized templates

by Duco :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, that put me on track. "howto.nl.rhtml" works, but then I discovered that "howto.nl-NL.rhtml" also works! However, it seems that one has to restart the server after creating new (localized) templates, otherwise Globalize won't see them. When I'm programming in a .NET enviroment i'm used to resetting the webserver all the time, but it is something unusual in a RoR setting :-) :-)

Duco

Joshua Wehner-3 wrote:
Try 'howto.nl.rhtml', that has worked for me in the past.


-- joshua