REPOST: fallback layout mechanism

Sorry for reposting but as I got no reply so far so I am just coming
to try my luck again.

I am doing a multi-lingual website which might have several layout
pages (language dependent)available. I want to do a mechanism to fall
back from one language to another default language if such layout
file
is missing. Any chance I can do an is_exist check on the layout? With
my current code I really want to just check it instead of catching a
MissingTemplate error.

only thing i see would be to do a simple File.exist?(file_name) on the
layout

but i would avoid to do this, that’s more of an organizational problem
to me, to make sure a language is fully implemented or not. if not, then
don’t show it

or keep a hash with ‘allowed’ languages somewhere
:en => true,
:fr => true,
:de => false etc.

this would depend on how many other parts of your site (views,
db-entries…) need to provide a translation.

you mean to say u want to check for the layout file exist or not?

Hmmm… looks good, but any chance if there is a non-default path for
views/layouts? I think it would be great if I could just have a
is_template_exist somewhere in the framework.

There are many websites would only implement a localized version for
certain page (like a company overview) and then skip the others, its
more a use case issue than a design issue I guess…

On Mar 17, 11:54 pm, Thorsten M. <rails-mailing-l…@andreas-

On Mar 19, 4:18 am, goodwill [email protected] wrote:

Hmmm… looks good, but any chance if there is a non-default path for
views/layouts? I think it would be great if I could just have a
is_template_exist somewhere in the framework.

There are many websites would only implement a localized version for
certain page (like a company overview) and then skip the others, its
more a use case issue than a design issue I guess…

I was wondering about this same thing in terms of having a simple
“theme engine” of sorts. You could add “themes” to an app simply by
having an override ability. So, if a file existed in /themes/users/
index.html.erb it could be set to override the one in /app/views/users/
index.html.erb…?

yes,

File.exist?(File.join(RAILS_ROOT, “app”, “views”, “layouts”,
“lang_en.html.erb”))

would give you a true or false, so you can decide what to do about it
it’s a bit primitive, but i can’t come up with a rails internal method
for layouts, so that would be what i would do if i had to.

but it would depend on lot’s of other details, i would avoid (as
mentioned) to do things on that level, maybe keeping the translations in
the db and deciding in the layout file, what to render.

do you really want to have different layouts or is the layout the same
(colors, positions…) and only the texts change?
what’s about other language dependent parts? like views or stuff in the
db? error messages?

can you allow to implement a language in parts? i would go for all or
nothing here, either a language exists and can be used without double
checking everything or not. but it’s up to you to decide

On Apr 2, 7:13 pm, Trevor T. [email protected] wrote:

I was wondering about this same thing in terms of having a simple
“theme engine” of sorts. You could add “themes” to an app simply by
having an override ability. So, if a file existed in /themes/users/
index.html.erb it could be set to override the one in /app/views/users/
index.html.erb…?

Hmm… perhaps this would do the trick?

http://weblog.rubyonrails.com/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths