Class: Lazier::Localizer

Inherits:
Object
  • Object
show all
Includes:
I18n
Defined in:
lib/lazier/localizer.rb

Overview

A utility class to localize messages

Instance Attribute Summary

Attributes included from I18n

#i18n_locale, #i18n_locales_path, #i18n_root

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from I18n

#i18n, #i18n=, #i18n_setup

Constructor Details

- (Localizer) initialize(root = nil, path = nil, locale = nil)

Initialize a new localizer.

Parameters:

  • root (Symbol) (defaults to: nil)

    The root level of the translation.

  • path (String) (defaults to: nil)

    The path where the translations are stored.

  • locale (String|Symbol) (defaults to: nil)

    The locale to use for localization.



17
18
19
20
# File 'lib/lazier/localizer.rb', line 17

def initialize(root = nil, path = nil, locale = nil)
  i18n_setup(root || :lazier, path || ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
  self.i18n = locale
end

Class Method Details

+ (String|R18n::Untranslated) localize(message, *args)

Localize a message.

Parameters:

  • message (String|Symbol)

    The message to localize.

  • args (Array)

    Optional arguments to localize the message.

Returns:

  • (String|R18n::Untranslated)

    The localized message.



27
28
29
# File 'lib/lazier/localizer.rb', line 27

def self.localize(message, *args)
  Lazier::Localizer.new.i18n.send(message, *args)
end

+ (String|R18n::Untranslated) localize_on_locale(locale, message, *args)

Localize a message in a specified locale.

Parameters:

  • locale (String|Symbol)

    The locale to use for localization.

  • message (String|Symbol)

    The message to localize.

  • args (Array)

    Optional arguments to localize the message.

Returns:

  • (String|R18n::Untranslated)

    The localized message.



37
38
39
# File 'lib/lazier/localizer.rb', line 37

def self.localize_on_locale(locale, message, *args)
  Lazier::Localizer.new(nil, nil, locale).i18n.send(message, *args)
end