Views w locale default template

[RAILS3]

I hesitate on how handling the locale view templates to default to
one language only …

sending admin emails will go only to one locale ‘en_GB’

should I set it up into the template name and set I18n.locale to
‘en_GB’

membership_renew.en_GB.html.erb

OR

whatever locale is used , if I have :

membership_renew.html

it will be the default ?

Kad K. wrote in post #999856:

[RAILS3]

I hesitate on how handling the locale view templates to default to
one language only …

sending admin emails will go only to one locale ‘en_GB’

should I set it up into the template name and set I18n.locale to
‘en_GB’

membership_renew.en_GB.html.erb

OR

whatever locale is used , if I have :

membership_renew.html

it will be the default ?

Hi, at least I didn’t completely get your problem.
The way I set a default locale is:

config.i18n.fallbacks = true
config.i18n.default_locale = :en

In application.rb

I have 3 languages and if one translation is not found it falls back to
english.

But again, I maybe didn’t get your goal.

Cheers.

On May 21, 2011, at 11:55 PM, Erwin [email protected] wrote:

differently. Here is a case :

Huh? That doesn’t sound correct to me. Specifying the locale in the
template filename seems very odd. Can you point me at documentation on
where this would required?

I agree , not very clear … I was referring to mailer template
views
I tested many cases and it seems I need to define .en_GB views
( including the locale)

I am using already the fallback…
config.i18n.fallbacks = true
config.i18n.default_locale = :en_EN

but I am concerned by mailer ? which seems to handle locale
differently. Here is a case :

I am logged in as current_user
I select :en_ES as locale for display
I visit the site …
and I some point the system need to send a message to the site
admin…

as mailer views I MUST have templates like : welcome.en_GB.html.erb
and NOT welcome.html.erb

Thanks Walter,

I was using a trick :

class ActionMailer::Localized < ActionMailer::Base
private

we override the template_path to render localized templates (since

rails does not support that :frowning: )

This thing is not testable since you cannot access the instance of

a mailer…
def initialize_defaults(method_name)
super
@template = “#{method_name}.#{I18n.locale}”
end
end

seems to be a very bad idea… I’m moving to another folder
structure,

views

user_mailer
en_GB
membership_renew.html.erb
membership_renew.text.erb
es_ES
membership_renew.html.erb
membership_renew.text.erb

so I need the template path to be:
@template = “#{ActionMailer::Base::template_root}/user_mailer/
{user.language || ‘en_GB’}.erb”

where should I write it ? directly in the mailer method ?..
will it handle the formats : html/text ?

def membership_renew(user, membership, clip)

==> @template = “#{ActionMailer::Base::template_root}/user_mailer/
{user.language || ‘en_GB’}/membership_renew.erb”
mail(:to => user.email, :subject => “Your Swing Analysis Request”)
do |format|
format.html { render :layout => “/mailer/sbga_user_mail” }
format.text
end
end

just tried … doesn’t work … @template is bypassed

ActionView::MissingTemplate: Missing template user_mailer/
membership_renew with
{:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml],
:formats=>[:html], :locale=>[:en_GB]}
in view paths “/Users/yves/Sites/rails/testsbga/app/views”

it should be looking for : template user_mailer/en_GB/
membership_renew …with {:handlers=>[:erb

the @template path seems to be build before the call to the mailer
action …