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, set default locale to Polish locale, load all translations shipped with library.



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

def init_i18n
  I18n.backend = Polish.i18n_backend_class.new
  I18n.default_locale = LOCALE
  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



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

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)


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

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



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

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

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

See I18n::translate



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

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