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
VERSION

Public Instance Methods

init_i18n() click to toggle source

Init Russian i18n: load all translations shipped with library.

# File lib/russian.rb, line 44
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 33
def locale
  LOCALE
end
localize(object, options = {}) click to toggle source

See I18n::localize

# File lib/russian.rb, line 60
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, "вещь", "вещи", "вещей", "вещи")
Russina.pluralize(5, "Произошла %n ошибка", "Произошло %n ошибки", "Произошло %n ошибок")
# File lib/russian.rb, line 76
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(n, *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 66
def strftime(object, format = :default)
  localize(object, { :format => check_strftime_format(object, format) })
end
t(key, options = {})
Alias for: translate
translate(key, options = {}) click to toggle source

See I18n::translate

# File lib/russian.rb, line 54
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 90
def transliterate(str)
  Russian::Transliteration.transliterate(str)
end
Also aliased as: translit

Protected Instance Methods

check_strftime_format(object, format) click to toggle source
# File lib/russian.rb, line 97
def check_strftime_format(object, format)
  %w(A a B b).each do |key|
    if format =~ /%\^#{key}/
      if RUBY_ENGINE == "jruby"
        format = format.gsub("%^#{key}", UnicodeUtils.upcase(localize(object, { :format => "%#{key}" } )))
      else
        format = format.gsub("%^#{key}", Unicode::upcase(localize(object, { :format => "%#{key}" } )))
      end
    end
  end

  format
end
locale_files() click to toggle source

Returns all locale files shipped with library

# File lib/russian.rb, line 112
def locale_files
  Dir[File.join(File.dirname(__FILE__), "russian", "locale", "**/*")]
end
pluralization_variants_to_hash(n, *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 118
def pluralization_variants_to_hash(n, *variants)
  variants.map!{ |variant| variant.gsub '%n', n.to_s }
  {
    :one => variants[0],
    :few => variants[1],
    :many => variants[2],
    :other => variants[3]
  }
end