com/posts/
show/34?locale=zh-CN). Alternatively, you can specify the locale parameter with a
custom route:
map.cms_page ':locale/*path_info', :controller => 'pages', :action => 'show'
This route would support a multilingual content-management system, where the
locale parameter determines the language and the *path_info segment looks up
the page in the database: http://example.com/en-US/about-us/contact-us.
3. Declare that the ActiveRecord class in question contains translated data:
class Page < ActiveRecord::Base
translates :title, :body
end
4. Find an object that needs translation; set the locale, set the text, and save the
object.
Locale.set 'es-MX'
@page.reload
@page.update_attributes! :body => "??Hola, mundo!"
5. The ActiveRecord accessors for the attributes specified by the translates
method now automatically check the current locale and look for the proper
translation:
<%= @page.body %>
# >> "??Hola, mundo!"
Globalize Example: An Address Book
To illustrate the use of Globalize for view translation all the way through an application,
we will construct a simple database that functions like an address book. First
we will develop the address book as an English-only application; later, we will see
what is involved in integrating Globalize and adding translations.
We will use a simple SQLite3 database file for storage:
config/database.yml
development:
adapter: sqlite3
database: db/globalize.
Pages:
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403