Skip to content

TalentBox/sequel_translatable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sequel_translatable

Translate model attributes for sequel.

Dependencies

  • Ruby >= 1.9.2
  • gem "i18n"
  • gem "sequel"

Usage

  • Assume a model with columns like this:

      MyModel.columns
      -> [:value_en, :value_fr, :name_nl]
    
  • Declare translatable attribute inside your model:

      class MyModel < Sequel::Model
        plugin :translatable, :value
      end
    
  • or for multiple attributes:

      class MyModel < Sequel::Model
        plugin :translatable, [:name, :value]
      end
    
  • then:

      I18n.locale
      -> :en
      m = MyModel.new value_en: "Item", value_fr: "Objet"
      m.value
      -> "Item"
      I18n.locale = :fr
      m.value
      -> "Objet"
      I18n.locale = :en_master
      m.value
      -> "Item"
      m.value = "Object"
      m.value_hash
      -> {en: "Object", fr: "Objet"}
    
  • You can ask the model class for the supported locales:

      MyModel.locales_for(:value)
      -> [:en, :fr]
      MyModel.locales_for(:name)
      -> [:nl]
    
  • You can also ask the model class for the translated attributes:

      MyModel.translated_attributes_for(:value)
      -> [:value_en, :value_fr]
      MyModel.translated_attributes_for(:name)
      -> [:name_nl]
    

Build Status

Build Status

License

sequel_translatable is Copyright © 2011 TalentBox SA. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Translate model attributes for sequel, fully tested.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages