jodosha / globalize forked from heythisisnate/globalize
- Source
- Commits
- Network (10)
- Issues (0)
- Downloads (1)
- Wiki (1)
- Graphs
-
Tree:
60bf457
globalize / README
| a727ed7f » | yannlugrin | 2006-10-13 | 1 | =Welcome to Globalize | |
| 2 | |||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 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. | ||||
| a727ed7f » | yannlugrin | 2006-10-13 | 7 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 8 | == How to use it | |
| a727ed7f » | yannlugrin | 2006-10-13 | 9 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 10 | Decide where you'd like globalize to store your translations. | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 11 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 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. | ||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 14 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 15 | To set this method as the default for add: | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 16 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 17 | Globalize::DbTranslate.keep_translations_in_model = true | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 18 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 19 | to your environment.rb. | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 20 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 21 | === In your models | |
| a727ed7f » | yannlugrin | 2006-10-13 | 22 | ||
| c5f9de6c » | saimonmoore | 2007-01-17 | 23 | #All translations stored in a separate table | |
| a727ed7f » | yannlugrin | 2006-10-13 | 24 | class Product < ActiveRecord::Base | |
| 25 | translates :name, :description, :specs | ||||
| 26 | end | ||||
| 27 | |||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 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 | |||||
| fa331b24 » | saimonmoore | 2007-01-22 | 35 | translates | |
| 36 | :name, :description, :specs | ||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 37 | end | |
| 38 | |||||
| a727ed7f » | yannlugrin | 2006-10-13 | 39 | Then: | |
| 40 | |||||
| fa331b24 » | saimonmoore | 2007-01-22 | 41 | Using <i>keep_translations_in_model = false</i>: | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 42 | ||
| a727ed7f » | yannlugrin | 2006-10-13 | 43 | Locale.set("en-US") | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 44 | prod = Product.find(1) | |
| a727ed7f » | yannlugrin | 2006-10-13 | 45 | ||
| 46 | <tt>prod.name -> "Meatballs"</tt> | ||||
| 47 | |||||
| 48 | Locale.set("es-ES") | ||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 49 | prod = Product.find(1) #Note: A reload of the model instance is required after a locale change. | |
| a727ed7f » | yannlugrin | 2006-10-13 | 50 | ||
| 51 | <tt>prod.name -> "Albondigas"</tt> | ||||
| 52 | |||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 53 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 54 | Using <i>keep_translations_in_model = true</i>: | |
| c5f9de6c » | saimonmoore | 2007-01-17 | 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 | |||||
| a727ed7f » | yannlugrin | 2006-10-13 | 65 | === In your views (or anywhere else) | |
| 66 | |||||
| 67 | Locale.set("he-IL") | ||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 68 | <%= "Thanks for ordering!".t %> -> "תודה על ההזמנה!" | |
| a727ed7f » | yannlugrin | 2006-10-13 | 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 | |||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 75 | See the wiki (http://www.globalize-rails.org/) for more documentation. | |
| a727ed7f » | yannlugrin | 2006-10-13 | 76 | ||
| fa331b24 » | saimonmoore | 2007-01-22 | 77 | == How to install | |
| a727ed7f » | yannlugrin | 2006-10-13 | 78 | ||
| 79 | From your rails app root directory: | ||||
| 80 | |||||
| 4cc24938 » | saimonmoore | 2007-03-12 | 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) | ||||
| a727ed7f » | yannlugrin | 2006-10-13 | 83 | ||
| 84 | ...and you're globalized, dude! | ||||
| 85 | |||||
| 86 | Optionally, try: | ||||
| 87 | |||||
| 88 | * <tt>rake test_plugins</tt> | ||||
| c5f9de6c » | saimonmoore | 2007-01-17 | 89 | * <tt>rake plugindoc</tt> | |
