Module: Spider::GetText

Defined in:
lib/spiderfw/i18n/gettext.rb

Class Method Summary collapse

Class Method Details

.in_domain(domain, &block) ⇒ Object

Executes a block of code in the given text_domain



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

def self.in_domain(domain, &block)
    prev_text_domain = FastGettext.text_domain
    FastGettext.text_domain = domain if FastGettext.translation_repositories.key?(domain)
    v = yield
    FastGettext.text_domain = prev_text_domain
    v
end

.restore_domain(domain) ⇒ Object

Sets the current text_domain; assumes the domain was already set before, so skips any check for domain validity



33
34
35
# File 'lib/spiderfw/i18n/gettext.rb', line 33

def self.restore_domain(domain)
    FastGettext.text_domain = domain
end

.set_domain(domain) ⇒ Object

Sets the current text_domain; return the previous domain



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

def self.set_domain(domain)
    prev_text_domain = FastGettext.text_domain
    FastGettext.text_domain = domain if FastGettext.translation_repositories.key?(domain)
    prev_text_domain
end

.update_pofiles(textdomain, files, app_version, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/spiderfw/i18n/gettext.rb', line 37

def self.update_pofiles(textdomain, files, app_version, options = {})
  require 'debugger'
  debugger
  puts options.inspect if options[:verbose]
        
  #write found messages to tmp.pot
  temp_pot = "tmp.pot"
  ::GetText::Tools::XGetText.run("-o", temp_pot, *files)
        
  #merge tmp.pot and existing pot
  po_root = options.delete(:po_root) || "po"
  FileUtils.mkdir_p(po_root)
  ::GetText::Tools::MsgMerge.run("#{po_root}/#{textdomain}.pot", temp_pot, app_version, options.dup)
        
  #update local po-files
  only_one_language = options.delete(:lang)
  if only_one_language
    ::GetText::Tools::MsgMerge.run("#{po_root}/#{only_one_language}/#{textdomain}.po", temp_pot, app_version, options.dup)
  else
    Dir.glob("#{po_root}/*/#{textdomain}.po") do |po_file|
      ::GetText::Tools::MsgMerge.run(po_file, temp_pot, app_version, options.dup)
    end
  end
        
  File.delete(temp_pot)
end