Module: Russian

Extended by:
Russian
Included in:
Russian
Defined in:
lib/russian.rb,
lib/russian/version.rb,
lib/russian/transliteration.rb

Defined Under Namespace

Modules: Transliteration, VERSION

Constant Summary

LOCALE =

Russian locale

ru
LOCALIZE_ABBR_MONTH_NAMES_MATCH =

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

/(%d|%e)(.*)(%b)/
LOCALIZE_MONTH_NAMES_MATCH =
/(%d|%e)(.*)(%B)/
LOCALIZE_STANDALONE_ABBR_DAY_NAMES_MATCH =
/^%a/
LOCALIZE_STANDALONE_DAY_NAMES_MATCH =
/^%A/

Instance Method Summary (collapse)

Instance Method Details

- (Object) init_i18n

Init Russian i18n: load all translations shipped with library.



30
31
32
33
34
35
36
37
# File 'lib/russian.rb', line 30

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

- (Object) locale

Russian locale



19
20
21
# File 'lib/russian.rb', line 19

def locale
  LOCALE
end

- (Object) localize(object, options = {}) Also known as: l

See I18n::localize



46
47
48
# File 'lib/russian.rb', line 46

def localize(object, options = {})
  I18n.localize(object, options.merge({ :locale => LOCALE }))
end

- (Object) pluralize(n, *variants) Also known as: p

Simple pluralization proxy

Usage:

Russian.pluralize(1, "вещь", "вещи", "вещей")
Russian.pluralize(3.14, "вещь", "вещи", "вещей", "вещи")

Raises:

  • (ArgumentError)


61
62
63
64
65
66
67
# File 'lib/russian.rb', line 61

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

- (Object) strftime(object, format = :default)

strftime() proxy with Russian localization



52
53
54
# File 'lib/russian.rb', line 52

def strftime(object, format = :default)
  localize(object, { :format => format })
end

- (Object) translate(key, options = {}) Also known as: t

See I18n::translate



40
41
42
# File 'lib/russian.rb', line 40

def translate(key, options = {})
  I18n.translate(key, options.merge({ :locale => LOCALE }))
end

- (Object) transliterate(str) Also known as: translit

Transliteration for russian language

Usage:

Russian.translit("рубин")
Russian.transliterate("рубин")


75
76
77
# File 'lib/russian.rb', line 75

def transliterate(str)
  Russian::Transliteration.transliterate(str)
end