Hello everyone, happy holidays if you are enjoying it right now.
I would like to make a simple language selector like this:
SELECTOR (current locale [:es])
Select Language: Español | Catala | French
Anyway, I’d like to get a few things:
It’s a Rails App pulling I18n and that makes running the gem with
svenfuchs routing-filter [1] is very well because it puts me the
locale (I18n.locale) this way:
www.mysite.com/en/foo/bar
www.mysite.com/en/foo/bar
www.mysite.com/ca/foo/bar
I would like the choice of locale was a mixture of user preferences
and browser locale preference :
- If you are a registered User has a field profile imposed by the
locale
language of the UI - if NOT logged look into some kind of cookie with his last choice
is
this good idea? - If you are not logged in and had not come before I look in the
language preferences of your browser with Rack:: locale Rack-contrib
[2] - If not registered, there is no cookie and the locale of your
browser
is not among those who managed the App, I show the UI with
I18n.default_locale (Established in initializers/i18n.rb) - Once we get the locale, set the SELECTOR above to be able to
change
the locale
(1) and (2) will manage in application_controller.rb
before_filter :set_user_language
def set_user_language
I18n.locale = logged_in? ? current_user.profile.language.to_s :
request.env[‘rack.locale’]
end
QUESTION:
When user click on selector Should pass several things:
- User logged in: We change the locale of the UI at that time and
update
his profile with the new selected locale. - User NOT logged. Store this choice of locale in some way for the
next
time How? Cookie, is a good idea? How is it done?
These two points refer to store the locale on a “permanent” for that
user, but another problem I have as the selector is constructed to
introduce the new locale:
Around here [3] suggested <% = link_to (“English”, url_for
(:overwrite_params => (: locale =>: en)))%>
But this [:overwrite_params] is deprecated [4].
How can i do this from Rails >= 2.3.8?
So the main question is: how to build the selector?
An idea is walk thought the [I18n.aviable_locales] array and exclude
the locale which is selected.
And for the text (Español, Spanish, Catala ,…) stored in a Hash
LOCALE_NAMES={: is => “Spanish”,: in => "Español ",…}
NOTE:
Use Rails 2.3.8 as the version of this gem (routing-filter) must be <=
v0.0.2
You will think it is bullshit, but to download a specific Tag of a gem
(yesterday I was a good time because I was missing the “v” before
0.0.2)
script/plugin install git://github.com/svenfuchs/routing-filter.git
–revision 'refs/tags/v0.0.2 ’
NOTE 2:
If you think my idea was wrong and you want to explain a better way,
I’ll be happy to listen and try to understand.
Many thanks for the help.
[1] GitHub - svenfuchs/routing-filter: routing-filter wraps around the complex beast that the Rails routing system is, allowing for unseen flexibility and power in Rails URL recognition and generation.
http://translate.googleusercontent.com/translate_c?hl=es&ie=UTF-8&sl=es&tl=en&u=http://github.com/svenfuchs/routing-filter&prev=_t&rurl=translate.google.com&twu=1&usg=ALkJrhiKS-2ErsP9K2S_S4LtNuUUmvo-_A
[2] GitHub - rack/rack-contrib: Contributed Rack Middleware and Utilities
http://translate.googleusercontent.com/translate_c?hl=es&ie=UTF-8&sl=es&tl=en&u=http://github.com/rack/rack-contrib&prev=_t&rurl=translate.google.com&twu=1&usg=ALkJrhj-0rvyBiYWxRyjbEjUqmG_E5qZ8A
[3] Issues · svenfuchs/routing-filter · GitHub # issue /
3
http://translate.googleusercontent.com/translate_c?hl=es&ie=UTF-8&sl=es&tl=en&u=http://github.com/svenfuchs/routing-filter/issues/closed&prev=_t&rurl=translate.google.com&twu=1&usg=ALkJrhiMvkzLphRNkAU97N6a9rhJPOqy5g#issue/3
[4] http://github
.com/rails/rails/commit/cbc0201a3e0145da51baa9d228d88633033521ce
http://translate.googleusercontent.com/translate_c?hl=es&ie=UTF-8&sl=es&tl=en&u=http://github.com/rails/rails/commit/cbc0201a3e0145da51baa9d228d88633033521ce&prev=_t&rurl=translate.google.com&twu=1&usg=ALkJrhhB1WA05czd1h8KAEOw9fCGE-V1NA