Prev | Current Page 399 | Next

Brad Ediger

"Advanced Rails"


Locale.set 'es-MX'
translations = {
"Address Book" => "Libreta de direcciones",
"New person" => "Nueva persona",
"Phone Numbers" => "N??meros de tel?©fono",
"Home" => "Casa",
"Office" => "Oficina",
"Mobile" => "M??vil",
"Address" => "Direcci??n",
"New Person" => "Nueva Persona",
"First name" => "Nombre",
"Last name" => "Apellido",
"Home phone" => "Tel?©fono de casa",
"Office phone" => "Tel?©fono oficina",
"Mobile phone" => "Tel?©fono m??vil",
"Country" => "Pa?­s",
"Save" => "Guardar",
"Address book is empty." => "Libreta de direcciones est?? vac?­a."
}
translations.each do |key, text|
ViewTranslation.update_all ['text = ?', text],
['tr_key = ? and language_id = ?', key, Locale.language.id]
end
268 | Chapter 8: i18n and L10n
As a final touch, we will add a language bar that enables the user to switch back and
forth between our supported locales. We create a partial for the language bar, and
update the master layout to include the language bar at the bottom of each page:
app/views/layouts/_language_bar.html.erb


<%= LOCALES.keys.map { |code|
link_to_unless code == Locale.language_code, code, url_for(:locale => code)
}.join(" | ") %>


Using url_for( ) in this manner relies on the fact that it will fill in any
missing required URL parameters from the URL of the current page.
Therefore, url_for(:locale => 'es') will point to the Spanish version
of the current page.


Pages:
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411