i18n locale picker

12 views
Skip to first unread message

hading2

unread,
Oct 20, 2011, 3:20:55 PM10/20/11
to bibapp-dev
Hi,

Claudia - haven't checked your emails yet, I've been busy with some
other stuff. I'll get to those later today or tomorrow.

I've added a local picker to the header at the same level as the
tagline but to the right. It will only appear when the application is
configured for multiple locales (as explained below). For this to work
some stuff has to happen:

- The available locales are configured now in config/locales.yml
(there is an example file). This is just a yaml file representing a
simple array of locales that you want Bibapp to be able to use, with
the default placed first. config/application.rb now uses this to set
I18n.available_locales and I18n.default_locale on start up. If there
is any problem with the file or it isn't present then Bibapp will just
default to English only. Of course all of the various *.yml files need
to be in place as well for things to work.

- Where the application controller sets the locale it now checks
against I18n.available_locales to make sure that it sets one that is
marked as available.

- There is a new translation key i18n:language:name. This key should
be set to the language corresponding to the translation (i.e. it's not
really translated from the English at all - it's more of a 'meta'
field).

Clicking on a link in the picker redirects a user to the same page but
in the selected locale.

Howard

Claudia Jürgen

unread,
Oct 21, 2011, 6:33:09 AM10/21/11
to bibap...@googlegroups.com
Hello Howard,

great, I updated the translation related files for this and the Romeo
color and vendor plugin make_resourcful.

The switch works ok apart from loading the root page
app/views/shared/_tagline_and_locales.html.haml where line #7 raised:
undefined method `to_sym' for nil:NilClass

7: %li= link_to_unless(locale.to_sym == params[:locale].to_sym,
t('i18n.language.name', :locale => locale), url_for(params.merge(:locale
=> locale)))

As the default locale and supported locales are configurable now, should
this configuration be taken into account in

config/routes.rb

We got

scope "(:locale)", :locale => /en|de/ do

there from the initial work on how to make i18n restful by using routes.
One could use the supported locales there and maybe add the default
locale to root.

Claudia

--
Claudia Juergen
Universitaetsbibliothek Dortmund
Eldorado
0231/755-4043
https://eldorado.tu-dortmund.de/

Howard Ding

unread,
Oct 21, 2011, 11:01:17 AM10/21/11
to bibap...@googlegroups.com
On 10/21/2011 5:33 AM, Claudia J�rgen wrote:
> Hello Howard,
>
> great, I updated the translation related files for this and the Romeo
> color and vendor plugin make_resourcful.
>
> The switch works ok apart from loading the root page
> app/views/shared/_tagline_and_locales.html.haml where line #7 raised:
> undefined method `to_sym' for nil:NilClass
>
> 7: %li= link_to_unless(locale.to_sym == params[:locale].to_sym,
> t('i18n.language.name', :locale => locale),
> url_for(params.merge(:locale => locale)))
>
Okay, that's an easy fix.

> As the default locale and supported locales are configurable now,
> should this configuration be taken into account in
>
> config/routes.rb
>
> We got
>
> scope "(:locale)", :locale => /en|de/ do
>
> there from the initial work on how to make i18n restful by using routes.
> One could use the supported locales there and maybe add the default
> locale to root.
>
Yes, something should probably happen here, although I'll need to
investigate exactly what. If we have access to I18n.available_locales in
routes.rb then I think it should be easy to handle, but I'll need to
check on that.

Howard

Howard Ding

unread,
Oct 21, 2011, 11:51:23 AM10/21/11
to bibap...@googlegroups.com
Hi,

These issues should be fixed now.

Howard

On 10/21/2011 5:33 AM, Claudia J�rgen wrote:

Reply all
Reply to author
Forward
0 new messages