Module: Slang::Helpers

Included in:
Slang
Defined in:
lib/slang.rb

Overview

Slang helpers module.

Instance Method Summary collapse

Instance Method Details

#locale_codeSymbol

Returns the locale code for the current Thread or Fiber.

Returns:



53
54
55
# File 'lib/slang.rb', line 53

def locale_code
  Thread.current[:slang_locale_code] ||= :en
end

#locale_code=(locale_code) ⇒ Object

Sets the current locale code (for the current Thread or Fiber).

Parameters:

  • locale (#to_sym)

    code



61
62
63
# File 'lib/slang.rb', line 61

def locale_code=(locale_code)
  Thread.current[:slang_locale_code] = locale_code.to_sym
end

#t(key, variable_hash = {}) ⇒ String

Get the content / translation for the given key.

In development mode, if a key is not found, a human-readable placeholder is returned (and the missing key is reported to the Slang service).

In production mode, if a key is not found, a placeholder string of the form “{locale_code:key}” is returned.

Parameters:

  • Key (#to_s)

    name, converted to a lowercase.

  • variable (Hash{#to_s => #to_s})

    hash (variable names to values)

Returns:

  • (String)

    translated string (frozen – dup if mutation is necessary)

Raises:



45
46
47
# File 'lib/slang.rb', line 45

def t(key, variable_hash={})
  Slang.internal_translate(key, variable_hash)
end