root/trunk/README

Revision 84, 2.3 kB (checked in by saimon, 2 years ago)

--Backporting for-1.2 features

Line 
1 =Welcome to Globalize
2
3 *Globalize* is a Ruby on Rails plugin designed to support globalized applications.
4 It supports translation into multiple languages (for both db content and controller
5 and view code) and localization of time, data, and numbers.
6 It's under the MIT License, same as Ruby on Rails.
7
8 == How to use it
9
10 Decide where you'd like globalize to store your translations.
11
12 By default globalize stores translations externally in a dedicated table but now
13 you also have the option to store translations within the model's own table.
14
15 To set this method as the default for add:
16
17  Globalize::DbTranslate.keep_translations_in_model = true
18
19 to your environment.rb.
20
21 === In your models
22
23   #All translations stored in a separate table
24   class Product < ActiveRecord::Base
25     translates :name, :description, :specs
26   end
27
28 or you can override the global setting per model by:
29
30   #All translations stored 'products' table
31   class Product < ActiveRecord::Base
32
33     self.keep_translations_in_model = true
34
35     translates
36     :name, :description, :specs
37   end
38
39 Then:
40
41 Using <i>keep_translations_in_model = false</i>:
42
43   Locale.set("en-US")
44   prod = Product.find(1)
45
46 <tt>prod.name -> "Meatballs"</tt>
47
48   Locale.set("es-ES")
49   prod = Product.find(1) #Note: A reload of the model instance is required after a locale change.
50
51 <tt>prod.name -> "Albondigas"</tt>
52
53
54 Using <i>keep_translations_in_model = true</i>:
55
56   Locale.set("en-US")
57   prod = Product.find(1)
58
59 <tt>prod.name -> "Meatballs"</tt>
60
61   Locale.set("es-ES")
62
63 <tt>prod.name -> "Albondigas"</tt> #Note: No reload of model is required
64
65 === In your views (or anywhere else)
66
67   Locale.set("he-IL")
68   <%= "Thanks for ordering!".t %> -> "תודה על ההזמנה!"
69   <%= "You've got %d items in your cart" / 5 %> -> "יש 5 מוש׹ים בסל שלך"
70
71   Locale.set("es-ES")
72   <%= Time.now.loc("%d %B %Y") %> -> "17 Octubre 2005"
73   <%= 12345.45.loc %> -> "12.345,45"
74
75 See the wiki (http://www.globalize-rails.org/) for more documentation.
76
77 == How to install
78
79 From your rails app root directory:
80
81 1. <tt>script/plugin install http://svn.globalize-rails.org/svn/globalize/trunk</tt>
82 2. <tt>rake globalize:setup</tt> (might take a while, about a minute or so)
83
84 ...and you're globalized, dude!
85
86 Optionally, try:
87
88 * <tt>rake test_plugins</tt>
89 * <tt>rake plugindoc</tt>
Note: See TracBrowser for help on using the browser.