class ReVIEW::I18n

Attributes

locale[RW]

Public Class Methods

i18n(*args) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 23
def self.i18n(*args)
  raise NotImplementedError, "I18n.i18n is obsoleted. Please use I18n.setup(locale, [ymlfile])"
end
locale=(locale) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 31
def self.locale=(locale)
  if @i18n
    @i18n.locale = locale
  else
    I18n.setup(locale)
  end
end
new(locale = nil) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 49
def initialize(locale = nil)
  @locale = locale
  load_default
end
setup(locale="ja", ymlfile = "locale.yml") click to toggle source
# File ../../../../../lib/review/i18n.rb, line 5
def self.setup(locale="ja", ymlfile = "locale.yml")
  @i18n = ReVIEW::I18n.new(locale)

  lfile = nil
  if ymlfile
    lfile = File.expand_path(ymlfile, Dir.pwd)

    # backward compatibility
    if !File.exist?(lfile) && (ymlfile == "locale.yml")
      lfile = File.expand_path("locale.yaml", Dir.pwd)
    end
  end

  if lfile && File.file?(lfile)
    @i18n.update_localefile(lfile)
  end
end
t(str, args = nil) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 27
def self.t(str, args = nil)
  @i18n.t(str, args)
end
Also aliased as: v, v
update(user_i18n, locale = nil) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 43
def self.update(user_i18n, locale = nil)
  @i18n.update(user_i18n, locale)
end
v(str, args = nil)
Alias for: t

Public Instance Methods

load_default() click to toggle source
# File ../../../../../lib/review/i18n.rb, line 54
def load_default
  load_file(File.expand_path "i18n.yml", File.dirname(__FILE__))
end
load_file(path) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 58
def load_file(path)
  @store = YAML.load_file(path)
end
t(str, args = nil) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 89
def t(str, args = nil)
  @store[@locale][str] % args
rescue
  str
end
update(user_i18n, locale = nil) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 80
def update(user_i18n, locale = nil)
  locale ||= @locale
  if @store[locale]
    @store[locale].merge!(user_i18n)
  else
    @store[locale] = user_i18n
  end
end
update_localefile(path) click to toggle source
# File ../../../../../lib/review/i18n.rb, line 62
def update_localefile(path)
  user_i18n = YAML.load_file(path)
  locale = user_i18n["locale"]
  if locale
    user_i18n.delete("locale")
    if @store[locale]
      @store[locale].merge!(user_i18n)
    else
      @store[locale] = user_i18n
    end
  else
    user_i18n.each do |key, values|
      raise KeyError, "Invalid locale file: #{path}" unless values.kind_of? Hash
      @store[key].merge!(values)
    end
  end
end