module Russian

Constants

LOCALE

Russian locale

LOCALIZE_ABBR_MONTH_NAMES_MATCH

Regexp machers for context-based russian month names and day names translation

LOCALIZE_MONTH_NAMES_MATCH
LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH
LOCALIZE_STANDALONE_DAY_NAMES_MATCH

Public Instance Methods

init_i18n() click to toggle source

Init Russian i18n: load all translations shipped with library.

# File lib/russian.rb, line 29
def init_i18n
  I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
  I18n::Backend::Simple.send(:include, I18n::Backend::Transliterator)

  I18n.load_path.unshift(*locale_files)

  I18n.reload!
end
l(object, options = {})
Alias for: localize
locale() click to toggle source

Russian locale

# File lib/russian.rb, line 18
def locale
  LOCALE
end
localize(object, options = {}) click to toggle source

See I18n::localize

# File lib/russian.rb, line 45
def localize(object, options = {})
  I18n.localize(object, options.merge({ :locale => LOCALE }))
end
Also aliased as: l
p(n, *variants)
Alias for: pluralize
pluralize(n, *variants) click to toggle source

Simple pluralization proxy

Usage:

Russian.pluralize(1, "вещь", "вещи", "вещей")
Russian.pluralize(3.14, "вещь", "вещи", "вещей", "вещи")
# File lib/russian.rb, line 60
def pluralize(n, *variants)
  raise ArgumentError, "Must have a Numeric as a first parameter" unless n.is_a?(Numeric)
  raise ArgumentError, "Must have at least 3 variants for pluralization" if variants.size < 3
  raise ArgumentError, "Must have at least 4 variants for pluralization" if (variants.size < 4 && n != n.round)
  variants_hash = pluralization_variants_to_hash(*variants)
  I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
end
Also aliased as: p
strftime(object, format = :default) click to toggle source

strftime() proxy with Russian localization

# File lib/russian.rb, line 51
def strftime(object, format = :default)
  localize(object, { :format => format })
end
t(key, options = {})
Alias for: translate
translate(key, options = {}) click to toggle source

See I18n::translate

# File lib/russian.rb, line 39
def translate(key, options = {})
  I18n.translate(key, options.merge({ :locale => LOCALE }))
end
Also aliased as: t
translit(str)
Alias for: transliterate
transliterate(str) click to toggle source

Transliteration for russian language

Usage:

Russian.translit("рубин")
Russian.transliterate("рубин")
# File lib/russian.rb, line 74
def transliterate(str)
  Russian::Transliteration.transliterate(str)
end
Also aliased as: translit

Protected Instance Methods

locale_files() click to toggle source

Returns all locale files shipped with library

# File lib/russian.rb, line 81
def locale_files
  Dir[File.join(File.dirname(__FILE__), "russian", "locale", "**/*")]
end
pluralization_variants_to_hash(*variants) click to toggle source

Converts an array of pluralization variants to a Hash that can be used with I18n pluralization.

# File lib/russian.rb, line 87
def pluralization_variants_to_hash(*variants)
  {
    :one => variants[0],
    :few => variants[1],
    :many => variants[2],
    :other => variants[3]
  }
end