Skip to content

Easily access (read and write) globalize3-translated fields without fiddling with locale

License

Notifications You must be signed in to change notification settings

jeromelefeuvre/easy_globalize3_accessors

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyGlobalize3Accessors

Introduction

Generator of easy accessor methods for models using Globalize3.

Use globalize_accessors with list of translated fields you want easily access to and extra :locales array listing locales for which you want the accessors to be generated.

This way a single form can be used to edit given model fields with all anticipated translations.

Installation

gem install easy_globalize3_accessors

Example

Definition like this:

class Product
  translates :title, :description
  globalize_accessors :locales => [:en, :pl], :attributes => [:title]
end

Gives you access to methods: title_pl, title_en, title_pl=, title_en= (and similar set of description_* methods). And they work seamlessly with Globalize3 (not even touching the “core” title, title= methods used by Globalize3 itself).

:locales and :attributes are optional. Default values are:

:locales => I18n.available_locales
:attributes => translated_attribute_names

which means that skipping all options will generate you accessor method for all translated fields and available languages

Always define accessors

If you wish to always define accessors and don’t want to call globalize_accessors method in every class, you can extend ActiveRecord::Base with such module:

module TranslatesWithAccessors

  def translates(*params)
    options = params.extract_options!
    options.reverse_merge!(:globalize_accessors => true)
    accessors = options.delete(:globalize_accessors)
    super
    globalize_accessors if accessors
  end

end

Licence

Copyright © 2009-2010 Tomek “Tomash” Stachewicz (tomash.wrug.eu), Robert Pankowecki (robert.pankowecki.pl) released under the MIT license

About

Easily access (read and write) globalize3-translated fields without fiddling with locale

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%