Namespace

Methods

R18n::Translated

Module to add i18n support to any class. It will be useful for ORM or R18n plugin with out-of-box i18n support.

Module can add proxy-methods to find translation in object methods. For example, if you class have title_en and title_ru methods, you can add proxy-method title, which will use title_ru for Russian users and title_en for English:

class Product
  include DataMapper::Resource
  property :title_ru, String
  property :title_en, String
  property :desciption_ru, String
  property :desciption_en, String

  include R18n::Translated
  translations :title, :desciption
end

# User know only Russian
R18n.set('ru')

product.title #=> Untranslated

# Set value to English (default) title
product.title_en = "Anthrax"
product.title #=> "Anthrax"
product.title.locale #=> Locale en (English)

# Set value to title on user locale (Russian)
product.title = "Сибирская язва"
product.title #=> "Сибирская язва"
product.title.locale #=> Locale ru (Russian)

product.title_en #=> "Anthrax"
product.title_ru #=> "Сибирская язва"

Proxy-method support all funtion from I18n: global and type filters, pluralization, variables. It also return TranslatedString or Untranslated.

By default it use R18n.get to get I18n object (so, you must set it before use model), but you can overwrite object r18n method to change default logic.

See R18n::Translated::Base for class method documentation.

Options

You can set option for proxy-method as Hash with keys;

Method translation will be more useful for options:

translation :title, :methods => {:ru => :russian, :en => :english}

Public Instance Methods

r18n() click to toggle source

Access to I18n object. By default return global I18n object from R18n.get.

# File lib/r18n-core/translated.rb, line 90
def r18n
  R18n.get
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.