Class: Abak::Flow::Locale

Inherits:
Object
  • Object
show all
Defined in:
lib/abak-flow/locale.rb

Constant Summary collapse

FILES =
File.join(File.dirname(__FILE__), "locales/*.{rb,yml}").freeze

Instance Method Summary collapse

Constructor Details

#initialize(locale) ⇒ Locale

Returns a new instance of Locale.



8
9
10
11
12
# File 'lib/abak-flow/locale.rb', line 8

def initialize(locale)
  I18n.enforce_available_locales = false
  I18n.load_path += Dir.glob(FILES)
  I18n.locale = locale
end

Instance Method Details

#error(object, key = nil, options = {}) ⇒ Object



26
27
28
29
# File 'lib/abak-flow/locale.rb', line 26

def error(object, key = nil, options = {})
  key.nil? ? I18n.t("#{namenize object}.fail", options)
    : I18n.t(key, options.merge(scope: "#{namenize object}.errors"))
end

#field(object, key) ⇒ Object



18
19
20
# File 'lib/abak-flow/locale.rb', line 18

def field(object, key)
  I18n.t(key, scope: "#{namenize object}.fields")
end

#name(object) ⇒ Object



14
15
16
# File 'lib/abak-flow/locale.rb', line 14

def name(object)
  I18n.t("#{namenize object}.name")
end

#success(object, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/abak-flow/locale.rb', line 31

def success(object, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  key = args[0]

  key.nil? ? I18n.t("#{namenize object}.success", options)
    : I18n.t(key, options.merge(scope: "#{namenize object}.success"))
end

#word(object, key, options = {}) ⇒ Object



22
23
24
# File 'lib/abak-flow/locale.rb', line 22

def word(object, key, options = {})
  I18n.t(key, options.merge(scope: "#{namenize object}.words"))
end