All Thumbs and No Fingers A bucket for all things

20Aug/090

Rails localisation bug

I've just gone through the challenge of working out what was wrong with the following piece of code:

<% form_tag :controller => '/' do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

Our client reported that on a signup page where they choose an alternative language it got redirected and they could never reach the page in their native language.

How can this happen you might ask?

Well the request includes some values within the url which are used as a key. Only if the key is valid is the controller allowed to complete the request. The issue is the combining of maintaining the key and switching the language.

As it happens its a very simple fix and was pointed out to me by Juliana.

<% form_tag :controller => request.request_uri do %>
				<%= t(:'txt.language') %> <%= select_tag("locale", options_for_select(LOCALES_AVAILABLE, I18n.locale), { :index => nil, :o nchange => 'this.form.submit()'}) %>
			<% end %>

In this fixed second example the alteration for the controller has been updated to direct the language selector to the controller of the current page. The documentation for this suggests that its broken on IIS (really should you be even trying to use this?) in fact I found that the source has had a significant amount of work go into it to work around the issue and even make it work on that webserver. Its a great little solution to ensure that the reloaded page is returned to the user in the state it was with the addition of the correct language.

   

Pages

Amazon Favs:

new posts

My Photos

IMG_0719

IMG_0706

IMG_0703

IMG_0700

More Photos

tag cloud

accessibility apple astronomy navigation observatory british beck bug council design development dunning kruger psychology elearning facebook flash flickr browsing web photos pictures general i8n induction wordpress opensource resuse iphone itunes javascript languages learning localisation localise mehrabian motorcycle music myth my_learning parking plan programing proxy rails rest socks software ssh star synth tech iphone travel theme threshold money value spending tips health weight obesity advice welcome words

categories

Blogroll

Life is too short

Friends