Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
Rails L10n | 267

>> Locale.set 'es-MX'
>> pp ViewTranslation.find(:all, :conditions =>
['text IS NULL AND language_id = ?', Locale.language.id]).map(&:tr_key)
["Address Book",
"New person",
"Phone Numbers",
"Home",
"Office",
"Mobile",
"Address",
"New Person",
"First name",
"Last name",
"Home phone",
"Office phone",
"Mobile phone",
"Country",
"Save",
"Address book is empty."]

We can take this list to our translator, get the translations back, and use the console
(or an administrative interface) to enter translations. This script, run at the Rails con-
sole, will set up our translations.


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
Free download pdf