Class: Ramaze::Tool::Gettext
- Defined in:
- lib/ramaze/contrib/gettext.rb
Defined Under Namespace
Modules: Parser
Class Method Summary collapse
-
.load(*locales) ⇒ Object
Load given locales from disk and save it into the dictionary.
-
.store(*locales) ⇒ Object
Stores given locales from the dictionary to disk.
-
.update ⇒ Object
Reloads given locales from the disk to refresh the dictionary.
Methods inherited from Localize
call, default_language, dictionary, file_for, languages, localize, localize_body, set_session_locale
Class Method Details
.load(*locales) ⇒ Object
Load given locales from disk and save it into the dictionary.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ramaze/contrib/gettext.rb', line 57 def self.load(*locales) Log.debug "loading locales: #{locales.inspect}" dict = trait[:dictionary] || {} locales.each do |locale| begin dict[locale] = ::MOFile.open(trait[:file] % locale) rescue Errno::ENOENT Log.error "couldn't load #{trait[:file] % locale}" dict[locale] = {} end end trait[:dictionary] = dict end |
.store(*locales) ⇒ Object
Stores given locales from the dictionary to disk.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ramaze/contrib/gettext.rb', line 88 def self.store(*locales) keys = [] dictionary.each do |locale, dict| keys.concat dict.keys end keys.delete "" data = ::GetText::RGetText.generate(keys.compact.uniq.sort.map {|x| [x] }) file = (trait[:file] % trait[:default_language]) + '.pot' File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd| fd.write data end rescue Errno::ENOENT => e Log.error e end |
.update ⇒ Object
Reloads given locales from the disk to refresh the dictionary.
76 77 78 79 80 81 82 83 84 |
# File 'lib/ramaze/contrib/gettext.rb', line 76 def self.update trait[:dictionary] = nil dictionary.each do |locale, dict| if dict.kind_of?(MOFile) Log.debug("Reloading #{dict.filename}") dict.update! end end end |