Module: Remarkable::I18n

Included in:
Remarkable
Defined in:
lib/remarkable/i18n.rb

Overview

This is a wrapper for I18n default functionality.

Remarkable shouldn’t rely on I18n default locale, because it might change throughout tests. So it’s Remarkable responsibility to hold its own locale and send it to I18n.

Instance Method Summary collapse

Instance Method Details

#add_locale(*locales) ⇒ Object

Add locale files to I18n and to load path, if it exists.

Examples

Remarkable.add_locale "path/to/locale"


16
17
18
19
# File 'lib/remarkable/i18n.rb', line 16

def add_locale(*locales)
  ::I18n.backend.load_translations *locales
  ::I18n.load_path += locales if ::I18n.respond_to?(:load_path)
end

#localeObject

Get Remarkable own locale.

Examples

Remarkable.locale = :en
Remarkable.locale #=> :en


38
39
40
# File 'lib/remarkable/i18n.rb', line 38

def locale
  @@locale
end

#locale=(locale) ⇒ Object

Set Remarkable own locale.

Examples

Remarkable.locale = :en


27
28
29
# File 'lib/remarkable/i18n.rb', line 27

def locale=(locale)
  @@locale = locale
end

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

Wrapper for I18n.localize



51
52
53
# File 'lib/remarkable/i18n.rb', line 51

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

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

Wrapper for I18n.translate



44
45
46
# File 'lib/remarkable/i18n.rb', line 44

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