gettext 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +9 -8
- data/ChangeLog +21 -0
- data/README.rdoc +7 -13
- data/Rakefile +7 -5
- data/benchmark/1.93.0.txt +8 -0
- data/benchmark/2.0.0.txt +8 -0
- data/benchmark/2.0.4.txt +11 -0
- data/benchmark/2.1.0.txt +11 -0
- data/benchmark/benchmark.rb +68 -0
- data/benchmark/test.rb +28 -0
- data/bin/rgettext +1 -2
- data/bin/rmsgfmt +1 -3
- data/bin/rmsgmerge +0 -2
- data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
- data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
- data/lib/gettext.rb +4 -6
- data/lib/gettext/cgi.rb +1 -3
- data/lib/gettext/core_ext/iconv.rb +2 -4
- data/lib/gettext/core_ext/string.rb +3 -3
- data/lib/gettext/parser/erb.rb +2 -53
- data/lib/gettext/parser/glade.rb +2 -99
- data/lib/gettext/parser/ruby.rb +7 -5
- data/lib/gettext/{class_info.rb → runtime/class_info.rb} +2 -1
- data/lib/gettext/{locale_path.rb → runtime/locale_path.rb} +1 -2
- data/lib/gettext/{mofile.rb → runtime/mofile.rb} +0 -0
- data/lib/gettext/{textdomain.rb → runtime/textdomain.rb} +3 -5
- data/lib/gettext/{textdomain_group.rb → runtime/textdomain_group.rb} +1 -1
- data/lib/gettext/{textdomain_manager.rb → runtime/textdomain_manager.rb} +11 -5
- data/lib/gettext/tools.rb +2 -2
- data/lib/gettext/tools/parser/erb.rb +52 -0
- data/lib/gettext/tools/parser/glade.rb +98 -0
- data/lib/gettext/tools/parser/ruby.rb +226 -0
- data/lib/gettext/tools/pomessage.rb +197 -0
- data/lib/gettext/{poparser.rb → tools/poparser.rb} +128 -122
- data/lib/gettext/tools/rgettext.rb +47 -92
- data/lib/gettext/tools/rmsgfmt.rb +2 -2
- data/lib/gettext/tools/rmsgmerge.rb +2 -2
- data/lib/gettext/utils.rb +1 -1
- data/lib/gettext/version.rb +2 -2
- data/po/bg/rgettext.po +68 -64
- data/po/bs/rgettext.po +69 -65
- data/po/ca/rgettext.po +67 -64
- data/po/cs/rgettext.po +73 -70
- data/po/de/rgettext.po +69 -65
- data/po/el/rgettext.po +67 -64
- data/po/eo/rgettext.po +67 -63
- data/po/es/rgettext.po +67 -63
- data/po/et/rgettext.po +66 -63
- data/po/fr/rgettext.po +69 -66
- data/po/hr/rgettext.po +77 -73
- data/po/hu/rgettext.po +68 -65
- data/po/it/rgettext.po +69 -65
- data/po/ja/rgettext.po +69 -65
- data/po/ko/rgettext.po +73 -70
- data/po/lv/rgettext.po +68 -65
- data/po/nb/rgettext.po +68 -65
- data/po/nl/rgettext.po +74 -70
- data/po/pt_BR/rgettext.po +69 -66
- data/po/rgettext.pot +52 -48
- data/po/ru/rgettext.po +69 -66
- data/po/sr/rgettext.po +68 -64
- data/po/sv/rgettext.po +59 -55
- data/po/ua/rgettext.po +69 -66
- data/po/vi/rgettext.po +67 -63
- data/po/zh/rgettext.po +65 -62
- data/po/zh_TW/rgettext.po +65 -62
- data/replace.rb +8 -0
- data/samples/cgi/hellolib.rb +1 -3
- data/samples/cgi/http.rb +2 -4
- data/samples/cgi/locale/bg/LC_MESSAGES/main.mo +0 -0
- data/samples/cgi/po/bg/#main.po# +84 -0
- data/samples/cgi/po/bg/main.po +1 -1
- data/samples/hello.rb +1 -1
- data/src/poparser.ry +2 -1
- data/test.rb +33 -0
- data/test/test_class_info.rb +1 -1
- data/test/test_gettext.rb +1 -0
- data/test/test_parser.rb +120 -75
- data/test/test_po_generation.rb +20 -0
- data/test/test_pomessage.rb +99 -0
- data/test/test_string.rb +8 -0
- data/test/testlib/gettext.rb +17 -0
- data/test/testlib/ngettext.rb +6 -1
- data/test/testlib/pgettext.rb +5 -0
- metadata +726 -985
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
=begin
|
|
3
|
+
parser/ruby.rb - parser for ruby script
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2003-2009 Masao Mutoh
|
|
6
|
+
Copyright (C) 2005 speakillof
|
|
7
|
+
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
|
|
8
|
+
|
|
9
|
+
You may redistribute it and/or modify it under the same
|
|
10
|
+
license terms as Ruby or LGPL.
|
|
11
|
+
|
|
12
|
+
=end
|
|
13
|
+
|
|
14
|
+
require 'irb/ruby-lex.rb'
|
|
15
|
+
require 'stringio'
|
|
16
|
+
require 'gettext/tools/pomessage'
|
|
17
|
+
|
|
18
|
+
module GetText
|
|
19
|
+
class RubyLexX < RubyLex # :nodoc: all
|
|
20
|
+
# Parser#parse resemlbes RubyLex#lex
|
|
21
|
+
def parse
|
|
22
|
+
until ( (tk = token).kind_of?(RubyToken::TkEND_OF_SCRIPT) && !@continue or tk.nil? )
|
|
23
|
+
s = get_readed
|
|
24
|
+
if RubyToken::TkSTRING === tk
|
|
25
|
+
def tk.value
|
|
26
|
+
@value
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def tk.value=(s)
|
|
30
|
+
@value = s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if @here_header
|
|
34
|
+
s = s.sub(/\A.*?\n/, '').sub(/^.*\n\Z/, '')
|
|
35
|
+
else
|
|
36
|
+
begin
|
|
37
|
+
s = eval(s)
|
|
38
|
+
rescue Exception
|
|
39
|
+
# Do nothing.
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
tk.value = s
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if $DEBUG
|
|
47
|
+
if tk.is_a? TkSTRING
|
|
48
|
+
$stderr.puts("#{tk}: #{tk.value}")
|
|
49
|
+
elsif tk.is_a? TkIDENTIFIER
|
|
50
|
+
$stderr.puts("#{tk}: #{tk.name}")
|
|
51
|
+
else
|
|
52
|
+
$stderr.puts(tk)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
yield tk
|
|
57
|
+
end
|
|
58
|
+
return nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Original parser does not keep the content of the comments,
|
|
62
|
+
# so monkey patching this with new token type and extended
|
|
63
|
+
# identify_comment implementation
|
|
64
|
+
RubyToken.def_token :TkCOMMENT_WITH_CONTENT, TkVal
|
|
65
|
+
|
|
66
|
+
def identify_comment
|
|
67
|
+
@ltype = "#"
|
|
68
|
+
get_readed # skip the hash sign itself
|
|
69
|
+
|
|
70
|
+
while ch = getc
|
|
71
|
+
if ch == "\n"
|
|
72
|
+
@ltype = nil
|
|
73
|
+
ungetc
|
|
74
|
+
break
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
return Token(TkCOMMENT_WITH_CONTENT, get_readed)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Extends PoMessage for RubyParser.
|
|
83
|
+
# Implements a sort of state machine to assist the parser.
|
|
84
|
+
module PoMessageForRubyParser
|
|
85
|
+
# Supports parsing by setting attributes by and by.
|
|
86
|
+
def set_current_attribute(str)
|
|
87
|
+
param = @param_type[@param_number]
|
|
88
|
+
raise ParseError, 'no more string parameters expected' unless param
|
|
89
|
+
set_value(param, str)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def init_param
|
|
93
|
+
@param_number = 0
|
|
94
|
+
self
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def advance_to_next_attribute
|
|
98
|
+
@param_number += 1
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
class PoMessage
|
|
102
|
+
include PoMessageForRubyParser
|
|
103
|
+
alias :initialize_old :initialize
|
|
104
|
+
def initialize(type)
|
|
105
|
+
initialize_old(type)
|
|
106
|
+
init_param
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
module RubyParser
|
|
111
|
+
extend self
|
|
112
|
+
|
|
113
|
+
ID = ['gettext', '_', 'N_', 'sgettext', 's_']
|
|
114
|
+
PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
|
|
115
|
+
MSGCTXT_ID = ['pgettext', 'p_']
|
|
116
|
+
MSGCTXT_PLURAL_ID = ['npgettext', 'np_']
|
|
117
|
+
|
|
118
|
+
# (Since 2.1.0) the 2nd parameter is deprecated
|
|
119
|
+
# (and ignored here).
|
|
120
|
+
# And You don't need to keep the pomessages as unique.
|
|
121
|
+
|
|
122
|
+
def parse(path, deprecated = []) # :nodoc:
|
|
123
|
+
lines = IO.readlines(path)
|
|
124
|
+
parse_lines(path, lines, deprecated)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def parse_lines(path, lines, deprecated = []) # :nodoc:
|
|
128
|
+
pomessages = deprecated
|
|
129
|
+
file = StringIO.new(lines.join + "\n")
|
|
130
|
+
rl = RubyLexX.new
|
|
131
|
+
rl.set_input(file)
|
|
132
|
+
rl.skip_space = true
|
|
133
|
+
#rl.readed_auto_clean_up = true
|
|
134
|
+
|
|
135
|
+
pomessage = nil
|
|
136
|
+
line_no = nil
|
|
137
|
+
last_comment = ''
|
|
138
|
+
reset_comment = false
|
|
139
|
+
rl.parse do |tk|
|
|
140
|
+
begin
|
|
141
|
+
case tk
|
|
142
|
+
when RubyToken::TkIDENTIFIER, RubyToken::TkCONSTANT
|
|
143
|
+
store_pomessage(pomessages, pomessage, path, line_no, last_comment)
|
|
144
|
+
if ID.include?(tk.name)
|
|
145
|
+
pomessage = PoMessage.new(:normal)
|
|
146
|
+
elsif PLURAL_ID.include?(tk.name)
|
|
147
|
+
pomessage = PoMessage.new(:plural)
|
|
148
|
+
elsif MSGCTXT_ID.include?(tk.name)
|
|
149
|
+
pomessage = PoMessage.new(:msgctxt)
|
|
150
|
+
elsif MSGCTXT_PLURAL_ID.include?(tk.name)
|
|
151
|
+
pomessage = PoMessage.new(:msgctxt_plural)
|
|
152
|
+
else
|
|
153
|
+
pomessage = nil
|
|
154
|
+
end
|
|
155
|
+
line_no = tk.line_no.to_s
|
|
156
|
+
when RubyToken::TkSTRING
|
|
157
|
+
pomessage.set_current_attribute tk.value if pomessage
|
|
158
|
+
when RubyToken::TkPLUS, RubyToken::TkNL
|
|
159
|
+
#do nothing
|
|
160
|
+
when RubyToken::TkCOMMA
|
|
161
|
+
pomessage.advance_to_next_attribute if pomessage
|
|
162
|
+
else
|
|
163
|
+
if store_pomessage(pomessages, pomessage, path, line_no, last_comment)
|
|
164
|
+
pomessage = nil
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
rescue
|
|
168
|
+
$stderr.print "\n\nError"
|
|
169
|
+
$stderr.print " parsing #{path}:#{tk.line_no}\n\t #{lines[tk.line_no - 1]}" if tk
|
|
170
|
+
$stderr.print "\n #{$!.inspect} in\n"
|
|
171
|
+
$stderr.print $!.backtrace.join("\n")
|
|
172
|
+
$stderr.print "\n"
|
|
173
|
+
exit 1
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
case tk
|
|
177
|
+
when RubyToken::TkCOMMENT_WITH_CONTENT
|
|
178
|
+
last_comment = "" if reset_comment
|
|
179
|
+
if last_comment.empty?
|
|
180
|
+
# new comment from programmer to translator?
|
|
181
|
+
comment1 = tk.value.lstrip
|
|
182
|
+
if comment1 =~ /^TRANSLATORS\:/
|
|
183
|
+
last_comment = $'
|
|
184
|
+
end
|
|
185
|
+
else
|
|
186
|
+
last_comment += "\n"
|
|
187
|
+
last_comment += tk.value
|
|
188
|
+
end
|
|
189
|
+
reset_comment = false
|
|
190
|
+
when RubyToken::TkNL
|
|
191
|
+
else
|
|
192
|
+
reset_comment = true
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
pomessages
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def target?(file) # :nodoc:
|
|
199
|
+
true # always true, as the default parser.
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
private
|
|
203
|
+
def store_pomessage(pomessages, pomessage, file_name, line_no, last_comment) #:nodoc:
|
|
204
|
+
if pomessage && pomessage.msgid
|
|
205
|
+
pomessage.sources << file_name + ":" + line_no
|
|
206
|
+
pomessage.add_comment(last_comment) unless last_comment.empty?
|
|
207
|
+
pomessages << pomessage
|
|
208
|
+
true
|
|
209
|
+
else
|
|
210
|
+
false
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
if __FILE__ == $0
|
|
217
|
+
require 'pp'
|
|
218
|
+
ARGV.each do |path|
|
|
219
|
+
pp GetText::RubyParser.parse(path)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
#rl = GetText::RubyLexX.new; rl.set_input(ARGF)
|
|
223
|
+
#rl.parse do |tk|
|
|
224
|
+
#p tk
|
|
225
|
+
#end
|
|
226
|
+
end
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
module GetText
|
|
2
|
+
class ParseError < StandardError
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
# Contains data related to the expression or sentence that
|
|
6
|
+
# is to be translated.
|
|
7
|
+
class PoMessage
|
|
8
|
+
PARAMS = {
|
|
9
|
+
:normal => [:msgid],
|
|
10
|
+
:plural => [:msgid, :msgid_plural],
|
|
11
|
+
:msgctxt => [:msgctxt, :msgid],
|
|
12
|
+
:msgctxt_plural => [:msgctxt, :msgid, :msgid_plural]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@@max_line_length = 70
|
|
16
|
+
|
|
17
|
+
# Sets the max line length.
|
|
18
|
+
def self.max_line_length=(len)
|
|
19
|
+
@@max_line_length = len
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Gets the max line length.
|
|
23
|
+
def self.max_line_length
|
|
24
|
+
@@max_line_length
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Required
|
|
28
|
+
attr_accessor :type # :normal, :plural, :msgctxt, :msgctxt_plural
|
|
29
|
+
attr_accessor :msgid
|
|
30
|
+
# Options
|
|
31
|
+
attr_accessor :msgid_plural
|
|
32
|
+
attr_accessor :msgctxt
|
|
33
|
+
attr_accessor :sources # ["file1:line1", "file2:line2", ...]
|
|
34
|
+
attr_accessor :comment
|
|
35
|
+
|
|
36
|
+
# Create the object. +type+ should be :normal, :plural, :msgctxt or :msgctxt_plural.
|
|
37
|
+
def initialize(type)
|
|
38
|
+
@type = type
|
|
39
|
+
@sources = []
|
|
40
|
+
@param_type = PARAMS[@type]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Support for extracted comments. Explanation s.
|
|
44
|
+
# http://www.gnu.org/software/gettext/manual/gettext.html#Names
|
|
45
|
+
def add_comment(new_comment)
|
|
46
|
+
if (new_comment and ! new_comment.empty?)
|
|
47
|
+
@comment ||= ""
|
|
48
|
+
@comment += new_comment
|
|
49
|
+
end
|
|
50
|
+
to_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Returns a parameter representation suitable for po-files
|
|
54
|
+
# and other purposes.
|
|
55
|
+
def escaped(param_name)
|
|
56
|
+
orig = self.send param_name
|
|
57
|
+
orig.gsub(/"/, '\"').gsub(/\r/, '')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Checks if the other translation target is mergeable with
|
|
61
|
+
# the current one. Relevant are msgid and translation context (msgctxt).
|
|
62
|
+
def ==(other)
|
|
63
|
+
other.msgid == self.msgid && other.msgctxt == self.msgctxt
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Merges two translation targets with the same msgid and returns the merged
|
|
67
|
+
# result. If one is declared as plural and the other not, then the one
|
|
68
|
+
# with the plural wins.
|
|
69
|
+
def merge(other)
|
|
70
|
+
return self unless other
|
|
71
|
+
raise ParseError, "Translation targets do not match: \n" \
|
|
72
|
+
" self: #{self.inspect}\n other: '#{other.inspect}'" unless self == other
|
|
73
|
+
if other.msgid_plural && !self.msgid_plural
|
|
74
|
+
res = other
|
|
75
|
+
unless (res.sources.include? self.sources[0])
|
|
76
|
+
res.sources += self.sources
|
|
77
|
+
res.add_comment(self.comment)
|
|
78
|
+
end
|
|
79
|
+
else
|
|
80
|
+
res = self
|
|
81
|
+
unless (res.sources.include? other.sources[0])
|
|
82
|
+
res.sources += other.sources
|
|
83
|
+
res.add_comment(other.comment)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
res
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Output the po message for the po-file.
|
|
90
|
+
def to_po_str
|
|
91
|
+
raise "msgid is nil." unless @msgid
|
|
92
|
+
raise "sources is nil." unless @sources
|
|
93
|
+
|
|
94
|
+
str = ""
|
|
95
|
+
# extracted comments
|
|
96
|
+
if comment
|
|
97
|
+
comment.split("\n").each do |comment_line|
|
|
98
|
+
str << "\n#. #{comment_line.strip}"
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# references
|
|
103
|
+
curr_pos = @@max_line_length
|
|
104
|
+
sources.each do |e|
|
|
105
|
+
if curr_pos + e.size > @@max_line_length
|
|
106
|
+
str << "\n#:"
|
|
107
|
+
curr_pos = 3
|
|
108
|
+
else
|
|
109
|
+
curr_pos += (e.size + 1)
|
|
110
|
+
end
|
|
111
|
+
str << " " << e
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# msgctxt, msgid, msgstr
|
|
115
|
+
str << "\nmsgctxt \"" << msgctxt << "\"" if msgctxt?
|
|
116
|
+
str << "\nmsgid \"" << escaped(:msgid) << "\"\n"
|
|
117
|
+
if plural?
|
|
118
|
+
str << "msgid_plural \"" << escaped(:msgid_plural) << "\"\n"
|
|
119
|
+
str << "msgstr[0] \"\"\n"
|
|
120
|
+
str << "msgstr[1] \"\"\n"
|
|
121
|
+
else
|
|
122
|
+
str << "msgstr \"\"\n"
|
|
123
|
+
end
|
|
124
|
+
str
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Returns true if the type is kind of msgctxt.
|
|
128
|
+
# And if this is a kind of msgctxt and msgctxt property
|
|
129
|
+
# is nil, then raise an RuntimeException.
|
|
130
|
+
def msgctxt?
|
|
131
|
+
if [:msgctxt, :msgctxt_plural].include? @type
|
|
132
|
+
raise "This PoMessage is a kind of msgctxt but the msgctxt property is nil. msgid: #{msgid}" unless @msgctxt
|
|
133
|
+
true
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Returns true if the type is kind of plural.
|
|
138
|
+
# And if this is a kind of plural and msgid_plural property
|
|
139
|
+
# is nil, then raise an RuntimeException.
|
|
140
|
+
def plural?
|
|
141
|
+
if [:plural, :msgctxt_plural].include? @type
|
|
142
|
+
raise "This PoMessage is a kind of plural but the msgid_plural property is nil. msgid: #{msgid}" unless @msgid_plural
|
|
143
|
+
true
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
# sets or extends the value of a translation target params like msgid,
|
|
150
|
+
# msgctxt etc.
|
|
151
|
+
# param is symbol with the name of param
|
|
152
|
+
# value - new value
|
|
153
|
+
def set_value(param, value)
|
|
154
|
+
send "#{param}=", (send(param) || '') + value.gsub(/\n/, '\n')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
public
|
|
158
|
+
# For backward comatibility. This doesn't support "comment".
|
|
159
|
+
# ary = [msgid1, "file1:line1", "file2:line"]
|
|
160
|
+
def self.new_from_ary(ary)
|
|
161
|
+
ary = ary.dup
|
|
162
|
+
msgid = ary.shift
|
|
163
|
+
sources = ary
|
|
164
|
+
type = :normal
|
|
165
|
+
msgctxt = nil
|
|
166
|
+
msgid_plural = nil
|
|
167
|
+
|
|
168
|
+
if msgid.include? "\004"
|
|
169
|
+
msgctxt, msgid = msgid.split(/\004/)
|
|
170
|
+
type = :msgctxt
|
|
171
|
+
end
|
|
172
|
+
if msgid.include? "\000"
|
|
173
|
+
ids = msgid.split(/\000/)
|
|
174
|
+
msgid = ids[0]
|
|
175
|
+
msgid_plural = ids[1]
|
|
176
|
+
if type == :msgctxt
|
|
177
|
+
type = :msgctxt_plural
|
|
178
|
+
else
|
|
179
|
+
type = :plural
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
ret = self.new(type)
|
|
183
|
+
ret.msgid = msgid
|
|
184
|
+
ret.sources = sources
|
|
185
|
+
ret.msgctxt = msgctxt
|
|
186
|
+
ret.msgid_plural = msgid_plural
|
|
187
|
+
ret
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def [](number)
|
|
191
|
+
param = @param_type[number]
|
|
192
|
+
raise ParseError, 'no more string parameters expected' unless param
|
|
193
|
+
send param
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
end
|
|
@@ -9,18 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
#
|
|
11
11
|
# DO NOT MODIFY!!!!
|
|
12
|
-
# This file is automatically generated by
|
|
13
|
-
# from
|
|
12
|
+
# This file is automatically generated by Racc 1.4.6
|
|
13
|
+
# from Racc grammer file "".
|
|
14
14
|
#
|
|
15
15
|
|
|
16
|
-
require 'racc/parser'
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
require 'racc/parser.rb'
|
|
19
17
|
module GetText
|
|
20
|
-
|
|
21
18
|
class PoParser < Racc::Parser
|
|
22
19
|
|
|
23
|
-
module_eval
|
|
20
|
+
module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 108)
|
|
24
21
|
include GetText
|
|
25
22
|
GetText.bindtextdomain("rgettext")
|
|
26
23
|
|
|
@@ -117,6 +114,7 @@ module_eval <<'..end src/poparser.ry modeval..ida5d3d657e2', 'src/poparser.ry',
|
|
|
117
114
|
encoding = detect_file_encoding(po_file)
|
|
118
115
|
args << "r:#{encoding}"
|
|
119
116
|
end
|
|
117
|
+
@po_file = po_file
|
|
120
118
|
parse(File.open(*args) {|io| io.read }, data, ignore_fuzzy)
|
|
121
119
|
end
|
|
122
120
|
|
|
@@ -129,31 +127,8 @@ module_eval <<'..end src/poparser.ry modeval..ida5d3d657e2', 'src/poparser.ry',
|
|
|
129
127
|
Encoding.default_external
|
|
130
128
|
end
|
|
131
129
|
private :detect_file_encoding
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
##### racc 1.4.5 generates ###
|
|
135
|
-
|
|
136
|
-
racc_reduce_table = [
|
|
137
|
-
0, 0, :racc_error,
|
|
138
|
-
0, 10, :_reduce_none,
|
|
139
|
-
2, 10, :_reduce_none,
|
|
140
|
-
2, 10, :_reduce_none,
|
|
141
|
-
2, 10, :_reduce_none,
|
|
142
|
-
2, 12, :_reduce_5,
|
|
143
|
-
1, 13, :_reduce_none,
|
|
144
|
-
1, 13, :_reduce_none,
|
|
145
|
-
4, 15, :_reduce_8,
|
|
146
|
-
5, 16, :_reduce_9,
|
|
147
|
-
2, 17, :_reduce_10,
|
|
148
|
-
1, 17, :_reduce_none,
|
|
149
|
-
3, 18, :_reduce_12,
|
|
150
|
-
1, 11, :_reduce_13,
|
|
151
|
-
2, 14, :_reduce_14,
|
|
152
|
-
1, 14, :_reduce_15 ]
|
|
153
|
-
|
|
154
|
-
racc_reduce_n = 16
|
|
155
|
-
|
|
156
|
-
racc_shift_n = 26
|
|
130
|
+
...end poparser.ry/module_eval...
|
|
131
|
+
##### State transition tables begin ###
|
|
157
132
|
|
|
158
133
|
racc_action_table = [
|
|
159
134
|
3, 13, 5, 7, 9, 15, 16, 17, 20, 17,
|
|
@@ -187,89 +162,112 @@ racc_goto_pointer = [
|
|
|
187
162
|
racc_goto_default = [
|
|
188
163
|
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ]
|
|
189
164
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
:
|
|
194
|
-
:
|
|
195
|
-
:
|
|
196
|
-
:
|
|
197
|
-
:
|
|
198
|
-
:
|
|
199
|
-
:
|
|
165
|
+
racc_reduce_table = [
|
|
166
|
+
0, 0, :racc_error,
|
|
167
|
+
0, 10, :_reduce_none,
|
|
168
|
+
2, 10, :_reduce_none,
|
|
169
|
+
2, 10, :_reduce_none,
|
|
170
|
+
2, 10, :_reduce_none,
|
|
171
|
+
2, 12, :_reduce_5,
|
|
172
|
+
1, 13, :_reduce_none,
|
|
173
|
+
1, 13, :_reduce_none,
|
|
174
|
+
4, 15, :_reduce_8,
|
|
175
|
+
5, 16, :_reduce_9,
|
|
176
|
+
2, 17, :_reduce_10,
|
|
177
|
+
1, 17, :_reduce_none,
|
|
178
|
+
3, 18, :_reduce_12,
|
|
179
|
+
1, 11, :_reduce_13,
|
|
180
|
+
2, 14, :_reduce_14,
|
|
181
|
+
1, 14, :_reduce_15 ]
|
|
200
182
|
|
|
201
|
-
|
|
183
|
+
racc_reduce_n = 16
|
|
184
|
+
|
|
185
|
+
racc_shift_n = 26
|
|
186
|
+
|
|
187
|
+
racc_token_table = {
|
|
188
|
+
false => 0,
|
|
189
|
+
:error => 1,
|
|
190
|
+
:COMMENT => 2,
|
|
191
|
+
:MSGID => 3,
|
|
192
|
+
:MSGCTXT => 4,
|
|
193
|
+
:MSGID_PLURAL => 5,
|
|
194
|
+
:MSGSTR => 6,
|
|
195
|
+
:STRING => 7,
|
|
196
|
+
:PLURAL_NUM => 8 }
|
|
202
197
|
|
|
203
198
|
racc_nt_base = 9
|
|
204
199
|
|
|
200
|
+
racc_use_result_var = true
|
|
201
|
+
|
|
205
202
|
Racc_arg = [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
203
|
+
racc_action_table,
|
|
204
|
+
racc_action_check,
|
|
205
|
+
racc_action_default,
|
|
206
|
+
racc_action_pointer,
|
|
207
|
+
racc_goto_table,
|
|
208
|
+
racc_goto_check,
|
|
209
|
+
racc_goto_default,
|
|
210
|
+
racc_goto_pointer,
|
|
211
|
+
racc_nt_base,
|
|
212
|
+
racc_reduce_table,
|
|
213
|
+
racc_token_table,
|
|
214
|
+
racc_shift_n,
|
|
215
|
+
racc_reduce_n,
|
|
216
|
+
racc_use_result_var ]
|
|
220
217
|
|
|
221
218
|
Racc_token_to_s_table = [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
219
|
+
"$end",
|
|
220
|
+
"error",
|
|
221
|
+
"COMMENT",
|
|
222
|
+
"MSGID",
|
|
223
|
+
"MSGCTXT",
|
|
224
|
+
"MSGID_PLURAL",
|
|
225
|
+
"MSGSTR",
|
|
226
|
+
"STRING",
|
|
227
|
+
"PLURAL_NUM",
|
|
228
|
+
"$start",
|
|
229
|
+
"msgfmt",
|
|
230
|
+
"comment",
|
|
231
|
+
"msgctxt",
|
|
232
|
+
"message",
|
|
233
|
+
"string_list",
|
|
234
|
+
"single_message",
|
|
235
|
+
"plural_message",
|
|
236
|
+
"msgstr_plural",
|
|
237
|
+
"msgstr_plural_line" ]
|
|
241
238
|
|
|
242
239
|
Racc_debug_parser = true
|
|
243
240
|
|
|
244
|
-
#####
|
|
241
|
+
##### State transition tables end #####
|
|
245
242
|
|
|
246
|
-
|
|
243
|
+
# reduce 0 omitted
|
|
247
244
|
|
|
248
|
-
|
|
245
|
+
# reduce 1 omitted
|
|
249
246
|
|
|
250
|
-
|
|
247
|
+
# reduce 2 omitted
|
|
251
248
|
|
|
252
|
-
|
|
249
|
+
# reduce 3 omitted
|
|
253
250
|
|
|
254
|
-
|
|
251
|
+
# reduce 4 omitted
|
|
255
252
|
|
|
256
|
-
module_eval
|
|
257
|
-
def _reduce_5(
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
module_eval(<<'.,.,', 'poparser.ry', 23)
|
|
254
|
+
def _reduce_5(val, _values, result)
|
|
255
|
+
@msgctxt = unescape(val[1]) + "\004"
|
|
256
|
+
|
|
257
|
+
result
|
|
260
258
|
end
|
|
261
259
|
.,.,
|
|
262
260
|
|
|
263
|
-
|
|
261
|
+
# reduce 6 omitted
|
|
264
262
|
|
|
265
|
-
|
|
263
|
+
# reduce 7 omitted
|
|
266
264
|
|
|
267
|
-
module_eval
|
|
268
|
-
def _reduce_8(
|
|
269
|
-
|
|
265
|
+
module_eval(<<'.,.,', 'poparser.ry', 35)
|
|
266
|
+
def _reduce_8(val, _values, result)
|
|
267
|
+
if @fuzzy and $ignore_fuzzy
|
|
270
268
|
if val[1] != ""
|
|
271
269
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
272
|
-
$stderr.print "
|
|
270
|
+
$stderr.print " #{@po_file}: msgid '#{val[1]}'\n"
|
|
273
271
|
else
|
|
274
272
|
on_message('', unescape(val[3]))
|
|
275
273
|
end
|
|
@@ -278,13 +276,14 @@ module_eval <<'.,.,', 'src/poparser.ry', 48
|
|
|
278
276
|
on_message(@msgctxt + unescape(val[1]), unescape(val[3]))
|
|
279
277
|
end
|
|
280
278
|
result = ""
|
|
281
|
-
|
|
279
|
+
|
|
280
|
+
result
|
|
282
281
|
end
|
|
283
282
|
.,.,
|
|
284
283
|
|
|
285
|
-
module_eval
|
|
286
|
-
def _reduce_9(
|
|
287
|
-
|
|
284
|
+
module_eval(<<'.,.,', 'poparser.ry', 52)
|
|
285
|
+
def _reduce_9(val, _values, result)
|
|
286
|
+
if @fuzzy and $ignore_fuzzy
|
|
288
287
|
if val[1] != ""
|
|
289
288
|
$stderr.print _("Warning: fuzzy message was ignored.\n")
|
|
290
289
|
$stderr.print "msgid = '#{val[1]}\n"
|
|
@@ -296,55 +295,62 @@ module_eval <<'.,.,', 'src/poparser.ry', 65
|
|
|
296
295
|
on_message(@msgctxt + unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4]))
|
|
297
296
|
end
|
|
298
297
|
result = ""
|
|
299
|
-
|
|
298
|
+
|
|
299
|
+
result
|
|
300
300
|
end
|
|
301
301
|
.,.,
|
|
302
302
|
|
|
303
|
-
module_eval
|
|
304
|
-
def _reduce_10(
|
|
305
|
-
|
|
303
|
+
module_eval(<<'.,.,', 'poparser.ry', 70)
|
|
304
|
+
def _reduce_10(val, _values, result)
|
|
305
|
+
if val[0].size > 0
|
|
306
306
|
result = val[0] + "\000" + val[1]
|
|
307
307
|
else
|
|
308
308
|
result = ""
|
|
309
309
|
end
|
|
310
|
-
|
|
310
|
+
|
|
311
|
+
result
|
|
311
312
|
end
|
|
312
313
|
.,.,
|
|
313
314
|
|
|
314
|
-
|
|
315
|
+
# reduce 11 omitted
|
|
315
316
|
|
|
316
|
-
module_eval
|
|
317
|
-
def _reduce_12(
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
module_eval(<<'.,.,', 'poparser.ry', 82)
|
|
318
|
+
def _reduce_12(val, _values, result)
|
|
319
|
+
result = val[2]
|
|
320
|
+
|
|
321
|
+
result
|
|
320
322
|
end
|
|
321
323
|
.,.,
|
|
322
324
|
|
|
323
|
-
module_eval
|
|
324
|
-
def _reduce_13(
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
module_eval(<<'.,.,', 'poparser.ry', 89)
|
|
326
|
+
def _reduce_13(val, _values, result)
|
|
327
|
+
on_comment(val[0])
|
|
328
|
+
|
|
329
|
+
result
|
|
327
330
|
end
|
|
328
331
|
.,.,
|
|
329
332
|
|
|
330
|
-
module_eval
|
|
331
|
-
def _reduce_14(
|
|
332
|
-
|
|
333
|
-
|
|
333
|
+
module_eval(<<'.,.,', 'poparser.ry', 97)
|
|
334
|
+
def _reduce_14(val, _values, result)
|
|
335
|
+
result = val.delete_if{|item| item == ""}.join
|
|
336
|
+
|
|
337
|
+
result
|
|
334
338
|
end
|
|
335
339
|
.,.,
|
|
336
340
|
|
|
337
|
-
module_eval
|
|
338
|
-
def _reduce_15(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
+
module_eval(<<'.,.,', 'poparser.ry', 101)
|
|
342
|
+
def _reduce_15(val, _values, result)
|
|
343
|
+
result = val[0]
|
|
344
|
+
|
|
345
|
+
result
|
|
341
346
|
end
|
|
342
347
|
.,.,
|
|
343
348
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
349
|
+
def _reduce_none(val, _values, result)
|
|
350
|
+
val[0]
|
|
351
|
+
end
|
|
347
352
|
|
|
348
353
|
end # class PoParser
|
|
354
|
+
end # module GetText
|
|
355
|
+
|
|
349
356
|
|
|
350
|
-
end # module GetText
|