Module: Russian

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

Defined Under Namespace

Modules: Transliteration, VERSION

Constant Summary collapse

LOCALE =

Russian locale

:'ru'

Instance Method Summary collapse

Instance Method Details

#i18n_backend_classObject

Returns custom backend class for usage with Russian library

See I18n::Backend



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

def i18n_backend_class
  I18n::Backend::Advanced
end

#init_i18nObject

Init Russian i18n: set custom backend, set default locale to Russian locale, load all translations shipped with library.



53
54
55
56
57
# File 'lib/russian.rb', line 53

def init_i18n
  I18n.backend = Russian.i18n_backend_class.new
  I18n.default_locale = LOCALE
  I18n.load_path.unshift(*locale_files)
end

#localeObject

Russian locale



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

def locale
  LOCALE
end

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

See I18n::localize



66
67
68
# File 'lib/russian.rb', line 66

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

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

Simple pluralization proxy

Usage:

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

Raises:

  • (ArgumentError)


81
82
83
84
85
86
87
# File 'lib/russian.rb', line 81

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

#strftime(object, format = :default) ⇒ Object

strftime() proxy with Russian localization



72
73
74
# File 'lib/russian.rb', line 72

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

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

See I18n::translate



60
61
62
# File 'lib/russian.rb', line 60

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

#transliterate(str) ⇒ Object Also known as: translit

Transliteration for russian language

Usage:

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


95
96
97
# File 'lib/russian.rb', line 95

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