Class: ReVIEW::I18n
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
- .i18n(*args) ⇒ Object
- .locale=(locale) ⇒ Object
- .setup(locale = "ja", ymlfile = "locale.yml") ⇒ Object
- .t(str, args = nil) ⇒ Object
- .update(user_i18n, locale = nil) ⇒ Object
-
.v ⇒ Object
for EPUBMaker backward compatibility.
Instance Method Summary collapse
-
#initialize(locale = nil) ⇒ I18n
constructor
A new instance of I18n.
- #load_default ⇒ Object
- #load_file(path) ⇒ Object
- #t(str, args = nil) ⇒ Object
- #update(user_i18n, locale = nil) ⇒ Object
- #update_localefile(path) ⇒ Object
Constructor Details
#initialize(locale = nil) ⇒ I18n
Returns a new instance of I18n.
50 51 52 53 |
# File 'lib/review/i18n.rb', line 50 def initialize(locale = nil) @locale = locale load_default end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
48 49 50 |
# File 'lib/review/i18n.rb', line 48 def locale @locale end |
Class Method Details
.i18n(*args) ⇒ Object
24 25 26 |
# File 'lib/review/i18n.rb', line 24 def self.i18n(*args) raise NotImplementedError, "I18n.i18n is obsoleted. Please use I18n.setup(locale, [ymlfile])" end |
.locale=(locale) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/review/i18n.rb', line 32 def self.locale=(locale) if @i18n @i18n.locale = locale else I18n.setup(locale) end end |
.setup(locale = "ja", ymlfile = "locale.yml") ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/review/i18n.rb', line 6 def self.setup(locale="ja", ymlfile = "locale.yml") @i18n = ReVIEW::I18n.new(locale) lfile = nil if ymlfile lfile = File.(ymlfile, Dir.pwd) # backward compatibility if !File.exist?(lfile) && (ymlfile == "locale.yml") lfile = File.("locale.yaml", Dir.pwd) end end if lfile && File.file?(lfile) @i18n.update_localefile(lfile) end end |
.t(str, args = nil) ⇒ Object
28 29 30 |
# File 'lib/review/i18n.rb', line 28 def self.t(str, args = nil) @i18n.t(str, args) end |
.update(user_i18n, locale = nil) ⇒ Object
44 45 46 |
# File 'lib/review/i18n.rb', line 44 def self.update(user_i18n, locale = nil) @i18n.update(user_i18n, locale) end |
.v ⇒ Object
for EPUBMaker backward compatibility
41 42 43 |
# File 'lib/review/i18n.rb', line 41 def self.t(str, args = nil) @i18n.t(str, args) end |
Instance Method Details
#load_default ⇒ Object
55 56 57 |
# File 'lib/review/i18n.rb', line 55 def load_default load_file(File. "i18n.yml", File.dirname(__FILE__)) end |
#load_file(path) ⇒ Object
59 60 61 |
# File 'lib/review/i18n.rb', line 59 def load_file(path) @store = YAML.load_file(path) end |
#t(str, args = nil) ⇒ Object
87 88 89 90 91 |
# File 'lib/review/i18n.rb', line 87 def t(str, args = nil) @store[@locale][str] % args rescue str end |
#update(user_i18n, locale = nil) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/review/i18n.rb', line 78 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) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/review/i18n.rb', line 63 def update_localefile(path) user_i18n = YAML.load_file(path) locale = user_i18n["locale"] if locale user_i18n.delete("locale") @store[locale].merge!(user_i18n) else key = user_i18n.keys.first if !user_i18n[key].kind_of? Hash raise KeyError, "Invalid locale file: #{path}" end @store.merge!(user_i18n) end end |