Module: Polish

Extended by:
Polish
Included in:
Polish
Defined in:
lib/polish.rb

Defined Under Namespace

Modules: VERSION

Constant Summary collapse

LOCALE =

Polish locale

:'pl'

Instance Method Summary collapse

Instance Method Details

#i18n_backend_classObject

Returns custom backend class for usage with Polish library

See I18n::Backend



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

def i18n_backend_class
  I18n::Backend::Advanced
end

#init_i18nObject

Init Polish i18n: set custom backend, load all translations shipped with library.



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

def init_i18n
  I18n.backend = Polish.i18n_backend_class.new
  I18n.load_path.unshift(*locale_files)
end

#localeObject

Polish locale



39
40
41
# File 'lib/polish.rb', line 39

def locale
  LOCALE
end

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

See I18n::localize



64
65
66
# File 'lib/polish.rb', line 64

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

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

Simple pluralization proxy

Usage:

Polish.pluralize(1, "dom", "domy", "domów")

Raises:

  • (ArgumentError)


78
79
80
81
82
83
# File 'lib/polish.rb', line 78

def pluralize(n, *variants)
  raise ArgumentError, "Must have a Numeric as a first parameter" unless n.is_a?(Numeric)
  raise ArgumentError, "Must have 3 variants for pluralization" if variants.size < 3
  variants_hash = pluralization_variants_to_hash(*variants)
  I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
end

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

strftime() proxy with Polish localization



70
71
72
# File 'lib/polish.rb', line 70

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

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

See I18n::translate



58
59
60
# File 'lib/polish.rb', line 58

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