Module: GetText::GladeParser

Extended by:
GetText
Defined in:
lib/gettext/parser/glade.rb

Constant Summary collapse

TARGET1 =
/<property.*translatable="yes">(.*)/
TARGET2 =
/(.*)<\/property>/
XML_RE =
/<\?xml/
GLADE_RE =
/glade-2.0.dtd/

Constants included from GetText

VERSION

Class Method Summary collapse

Methods included from GetText

N_, Nn_, _, add_default_locale_path, bindtextdomain, callersrc, cgi, cgi=, charset=, create_mofiles, gettext, locale, locale=, msgmerge, msgmerge_all, n_, ngettext, output_charset, output_charset=, rgettext, rmsgfmt, rmsgmerge, s_, set_cgi, set_charset, set_locale, set_output_charset, setlocale, sgettext, textdomain, update_pofiles

Class Method Details

.add_target(val, file, line_no, targets) ⇒ Object

:nodoc:



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/gettext/parser/glade.rb', line 84

def add_target(val, file, line_no, targets) # :nodoc:
  return unless val.size > 0
  assoc_data = targets.assoc(val)
  val = CGI.unescapeHTML(val)
  if assoc_data 
    targets[targets.index(assoc_data)] = assoc_data << "#{file}:#{line_no}"
  else
    targets << [val.gsub(/\n/, '\n'), "#{file}:#{line_no}"]
  end
  targets
end

.parse(file, targets = []) ⇒ Object

:nodoc:



24
25
26
27
# File 'lib/gettext/parser/glade.rb', line 24

def parse(file, targets = []) # :nodoc: 
  lines = IO.readlines(file)
  parse_lines(file, lines, targets)
end

.parse_lines(file, lines, targets) ⇒ Object

from ary of lines.



30
31
32
33
34
35
36
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
63
# File 'lib/gettext/parser/glade.rb', line 30

def parse_lines(file, lines, targets) # :nodoc:
  cnt = 0
  target = false
  line_no = 0
  val = nil
  
  loop do 
    line = lines.shift
    break unless line
    
    cnt += 1
    if TARGET1 =~ line
      line_no = cnt
      val = $1 + "\n"
      target = true
      if TARGET2 =~ $1
        val = $1
        add_target(val, file, line_no, targets)
        val = nil
        target = false
      end
    elsif target
      if TARGET2 =~ line
        val << $1
        add_target(val, file, line_no, targets)
        val = nil
        target = false
      else
        val << line
      end
    end
  end
  targets
end

.target?(file) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gettext/parser/glade.rb', line 68

def target?(file) # :nodoc:
  data = IO.readlines(file)
  if XML_RE =~ data[0]
	if GLADE_RE =~ data[1]
	  return true
	else
	  if File.extname(file) == '.glade'
 raise _("%s is not glade-2.0 format.") % [file]
	  end
	  return false
	end
  else
	return false
  end
end