Sha256: 1e398062137e3833ac3c957979072ca280601a319ec31180ea03024fb3709356

Contents?: true

Size: 745 Bytes

Versions: 1

Compression:

Stored size: 745 Bytes

Contents

# -*- coding: utf-8 -*-
require 'yaml'

module ReVIEW
  class I18n
    def self.setup
      lfile = File.expand_path "locale.yml", Dir.pwd
      # backward compatibility
      lfile = File.expand_path "locale.yaml", Dir.pwd unless File.exist?(lfile)
      user_i18n = YAML.load_file(lfile)
      I18n.i18n user_i18n["locale"], user_i18n
    rescue
      I18n.i18n "ja"
    end

    def self.i18n(locale, user_i18n = {})
      locale ||= "ja"
      i18n_yaml_path = File.expand_path "i18n.yml", File.dirname(__FILE__)
      @i18n = YAML.load_file(i18n_yaml_path)[locale]
      if @i18n
        @i18n.merge!(user_i18n)
      end
    end

    def self.t(str, args = nil)
      @i18n[str] % args
    rescue
      str
    end
  end

  I18n.setup
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
review-1.4.0 lib/review/i18n.rb