Module: Nls

Defined in:
lib/dm_core/nls.rb

Overview


Constant Summary collapse

CONTINENTS =
['Europe', 'North America', 'South America', 'Oceania', 'Asia', 'Africa', 'Antartica']

Instance Method Summary collapse

Instance Method Details

#nls(message_key, options = {}) ⇒ Object

default scope the msg lookup to the current theme




9
10
11
12
13
14
# File 'lib/dm_core/nls.rb', line 9

def nls(message_key, options = {})
  #--- look up message in the scope of current theme, fallback to parent theme
  key       = "#{Account.current.current_theme}.#{message_key.to_s}"
  fallback  = Account.current.parent_theme ? "#{Account.current.parent_theme}.#{message_key.to_s}" : "translation missing: #{key}"
  I18n.t(key, options.merge(default: fallback.to_sym))     
end

#nls?(message_key) ⇒ Boolean

Check if the message exists


Returns:

  • (Boolean)


18
19
20
21
# File 'lib/dm_core/nls.rb', line 18

def nls?(message_key)
  key       = "#{Account.current.current_theme}.#{message_key.to_s}"
  I18n.t key, :raise => true rescue false
end

#nls_flag_image(lang = nil) ⇒ Object

Helper to generate the image_tag for a language flag.

nls_flag_image(:en)



26
27
28
# File 'lib/dm_core/nls.rb', line 26

def nls_flag_image(lang = nil)
  image_tag(DmCore::Language.flag_image(lang))
end