Module: I18N

Defined in:
lib/primate/i18n.rb

Overview

Internationalization support

Defined Under Namespace

Modules: Locale

Class Method Summary collapse

Class Method Details

.localeLocale

Locale accessor

Returns:

  • (Locale)

    Locale accessor object



34
35
36
# File 'lib/primate/i18n.rb', line 34

def locale
  Locale
end

.set_current(i18n_obj) ⇒ void

This method returns an undefined value.

Set the current i18n instance (called by framework)

Parameters:

  • i18n_obj (Object)

    JavaScript i18n object from the runtime



12
13
14
# File 'lib/primate/i18n.rb', line 12

def set_current(i18n_obj)
  @current = i18n_obj
end

.t(key, params = nil) ⇒ String

Translate a key with optional parameters

Parameters:

  • key (String)

    Translation key

  • params (Hash) (defaults to: nil)

    Interpolation parameters

Returns:

  • (String)

    Translated string



21
22
23
24
25
26
27
28
29
# File 'lib/primate/i18n.rb', line 21

def t(key, params = nil)
  return key unless @current

  if params.nil?
    @current.t(key)
  else
    @current.t(key, params.to_json)
  end
end