Globalize extension
Globalize extension add useful methods to the great Globalize plugin for Ruby On Rails.
Install Globalize extension
Stable version
svn export svn://opensvn.liquid-concept.com/globalize_extension/stable vendor/plugins/globalize_extension
Or download and extract globalize_extension.zip into your vendor/plugins directory.
Edge version
svn co svn://opensvn.liquid-concept.com/globalize_extension/trunk vendor/plugins/globalize_extension
Support
If you encounter any problems with this plugin, feel free to post a new ticket.
Readme
The goal of this extension is to let you switch the language of a model during execution. Then you can have content in more than one language in the same page without pain.
Previous language are cached in the instance, then you can modify your model in more than one language and save all the modifications at once by a call to the standard save method!
A side effect of the extension is that it is less error prone because you can set the language once at begining of the page, then switch during a block using Locale.switch('fr') {#my code for French}.
Main method is 'Active Record#switch_language?(code, &block)' which :
- translate the mode in the 'code' language
- translate the loaded associations too
- if a block is passed :
- modifiy Locale language to current one
- execute the block
- revert model, Locale and associations to previous language
Exemple :
Locale.set('fr')
@document.title = "Nouvelles du jour"
@document.switch_language('en') do
@document.title = "Today News"
@document.title #--> Today News
end
@document.title #--> Nouvelle du jour
# And then save everything:
@document.save
Globalize Extension? add the following methods to Globalize plugin
defined in active_record_ex.rb :
- .globalized? --> return true if the model has translated fields.
- #language_code --> return the model current language code
- #switch_language --> load another translation for this model (cache the current values) switch_language is defined in Active Record? because it follow association. Then translatiosn doesen't break if a product is not translated in the middle of the chain.
- #operate_switch_language_on_associations --> translates loaded associations (private)
defined in db_translate_ex.rb
Globalize::DbTranslate::Class Methods?
- #translates --> add the after_save :save_translations callback
Globalize::DbTranslate::Translate Class Methods?
- #after_switch_language --> callback occurs after the translation. Useful if you have non-standard association.
- #before_switch_language --> callback occurs before the translation.
- #find_every --> override to support translations (private)
Globalize::DbTranslate::Translate Object Methods?
- #after_switch_language --> callback
- #before_switch_language --> callback
- #set_globalized_attributes --> So you can send a params dict which contain keys like { :title => {:fr => 'Mon Titre', :en => 'My Title'} }
- #save_translations --> save all translations for the model
- #translation_cache[=] --> accessor to the @@translation_cache (protected)
- #operate_switch_language --> load other translations (private)
defined in local_ex.rb :
- Globalize::Locale.switch --> switch the language code to 'code' during the block, then revert to previous language.
- Globalize::Locale.country_options_for_select --> ???
License
Authors : Olivier Amblet <olivier.amblet@liquid-concept.com>, Yann Lugrin <yann.lugrin@liquid-concept.com>
You can use Globalize under the terms of the MIT license (same as rails)
This is an extension to the Globalize plugins from Joshua Harvey
Copyright (c) 2006 Olivier Amblet, Yann Lugrin, Liquid Concept S.à.r.l.
This is the MIT license, the license Ruby on Rails itself is licensed under.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Attachments
- globalize_extension.zip (16.4 kB) -
Globalize Extension version 0.9.0
, added by olivier on 07/08/06 12:26:56.
