Class: ReVIEW::I18n

Inherits:
Object show all
Defined in:
lib/review/i18n.rb

Class Method Summary collapse

Class Method Details

.i18n(locale, user_i18n = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/review/i18n.rb', line 16

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

.setupObject



6
7
8
9
10
11
12
13
14
# File 'lib/review/i18n.rb', line 6

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

.t(str, args = nil) ⇒ Object



25
26
27
28
29
# File 'lib/review/i18n.rb', line 25

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