Sha256: 2517c1b1b6afa704c8bdc491c323a38bca0c60c00853b71f1783521694747d97

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

# encoding: utf-8
#
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

module Lazier
# A utility class to localize messages
  class Localizer
    include Lazier::I18n

    # Initialize a new localizer.
    #
    # @param root [Symbol] The root level of the translation.
    # @param path [String] The path where the translations are stored.
    # @param locale [String|Symbol] The locale to use for localization.
    def initialize(root = nil, path = nil, locale = nil)
      root ||= :lazier
      path ||= ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")
      self.i18n_setup(root, path)
      self.i18n = locale
    end

    # Localize a message.
    #
    # @param message [String|Symbol] The message to localize.
    # @param args [Array] Optional arguments to localize the message.
    # @return [String|R18n::Untranslated] The localized message.
    def self.localize(message, *args)
      self.new.i18n.send(message, *args)
    end

    # Localize a message in a specified locale.
    #
    # @param locale [String|Symbol] The locale to use for localization.
    # @param message [String|Symbol] The message to localize.
    # @param args [Array] Optional arguments to localize the message.
    # @return [String|R18n::Untranslated] The localized message.
    def self.localize_on_locale(locale, message, *args)
      self.new(nil, nil, locale).i18n.send(message, *args)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lazier-2.8.1 lib/lazier/localizer.rb
lazier-2.8.0 lib/lazier/localizer.rb
lazier-2.7.0 lib/lazier/localizer.rb
lazier-2.6.7 lib/lazier/localizer.rb
lazier-2.6.6 lib/lazier/localizer.rb
lazier-2.6.5 lib/lazier/localizer.rb