gettext 2.3.9 → 3.0.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/.yardopts +1 -0
- data/README.rdoc +28 -23
- data/Rakefile +29 -21
- data/doc/text/news.md +57 -0
- data/gettext.gemspec +1 -1
- data/lib/gettext.rb +13 -29
- data/lib/gettext/cgi.rb +1 -1
- data/lib/gettext/{runtime/class_info.rb → class_info.rb} +1 -1
- data/lib/gettext/{runtime/locale_path.rb → locale_path.rb} +1 -2
- data/lib/gettext/{runtime/mo.rb → mo.rb} +18 -33
- data/lib/gettext/{tools/po.rb → po.rb} +1 -1
- data/lib/gettext/{tools/po_entry.rb → po_entry.rb} +8 -4
- data/lib/gettext/{tools/poparser.rb → po_parser.rb} +41 -44
- data/lib/gettext/{runtime/textdomain.rb → text_domain.rb} +6 -16
- data/lib/gettext/text_domain_group.rb +26 -0
- data/lib/gettext/{runtime/textdomain_manager.rb → text_domain_manager.rb} +40 -40
- data/lib/gettext/tools.rb +1 -182
- data/lib/gettext/tools/msgfmt.rb +1 -1
- data/lib/gettext/tools/msginit.rb +1 -1
- data/lib/gettext/tools/msgmerge.rb +2 -221
- data/lib/gettext/tools/parser/erb.rb +49 -30
- data/lib/gettext/tools/parser/glade.rb +44 -36
- data/lib/gettext/tools/parser/ruby.rb +126 -37
- data/lib/gettext/tools/task.rb +225 -0
- data/lib/gettext/tools/xgettext.rb +25 -28
- data/lib/gettext/version.rb +1 -1
- data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
- data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
- data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
- data/locale/de/LC_MESSAGES/gettext.mo +0 -0
- data/locale/el/LC_MESSAGES/gettext.mo +0 -0
- data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
- data/locale/es/LC_MESSAGES/gettext.mo +0 -0
- data/locale/et/LC_MESSAGES/gettext.mo +0 -0
- data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
- data/locale/it/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
- data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
- data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
- data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
- data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
- data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
- data/locale/sv/LC_MESSAGES/gettext.mo +0 -0
- data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
- data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
- data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
- data/po/gettext.pot +171 -97
- data/samples/hello.rb +3 -2
- data/samples/hello2.rb +2 -1
- data/samples/hello_gtk2.rb +4 -1
- data/samples/hello_gtk_builder.rb +32 -0
- data/samples/hello_gtk_builder.ui +46 -0
- data/samples/hello_noop.rb +2 -1
- data/samples/hello_plural.rb +2 -1
- data/samples/hello_tk.rb +2 -1
- data/src/{poparser.ry → po_parser.ry} +31 -35
- data/test/fixtures/N_.rb +1 -1
- data/test/fixtures/_/double_quote_in_double_quote.rb +32 -0
- data/test/fixtures/_/double_quote_in_single_quote.rb +32 -0
- data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +36 -0
- data/test/fixtures/_/middle_new_line.rb +32 -0
- data/test/fixtures/_/multiple_lines_literal.rb +35 -0
- data/test/fixtures/_/multiple_messages_in_same_line.rb +32 -0
- data/test/fixtures/_/multiple_same_messages.rb +36 -0
- data/{lib/gettext/runtime/mofile.rb → test/fixtures/_/one_new_line.rb} +12 -6
- data/test/fixtures/{multi_textdomain.rb → multi_text_domain.rb} +1 -1
- data/test/fixtures/non_ascii.rb +1 -1
- data/test/fixtures/simple.rb +1 -1
- data/test/fixtures/untranslated.rb +1 -1
- data/test/gettext-test-utils.rb +1 -24
- data/test/po/ja/_.po +63 -13
- data/test/po/ja/non_ascii.po +2 -3
- data/test/po/ja/untranslated.po +1 -1
- data/test/test_class_info.rb +2 -2
- data/test/test_gettext.rb +11 -11
- data/test/test_mo.rb +2 -2
- data/test/test_parser.rb +93 -96
- data/test/test_po_entry.rb +237 -146
- data/test/test_po_parser.rb +107 -98
- data/test/test_string.rb +1 -1
- data/test/{test_textdomain_bind.rb → test_text_domain_bind.rb} +6 -6
- data/test/{test_textdomain_multi.rb → test_text_domain_multi.rb} +5 -5
- data/test/{test_textdomain_toplevel.rb → test_text_domain_toplevel.rb} +1 -1
- data/test/test_thread.rb +1 -1
- data/test/tools/files/simple_translation.rb +1 -1
- data/test/{parser → tools/parser}/test_ruby.rb +110 -14
- data/test/tools/test_msgmerge.rb +17 -276
- data/test/tools/test_po.rb +1 -1
- data/test/tools/test_xgettext.rb +175 -144
- metadata +59 -33
- data/lib/gettext/core_ext/iconv.rb +0 -110
- data/lib/gettext/core_ext/string.rb +0 -91
- data/lib/gettext/parser/erb.rb +0 -5
- data/lib/gettext/parser/glade.rb +0 -5
- data/lib/gettext/parser/ruby.rb +0 -172
- data/lib/gettext/runtime/textdomain_group.rb +0 -26
- data/lib/gettext/task.rb +0 -203
- data/lib/gettext/utils.rb +0 -39
- data/test/test_po_generation.rb +0 -45
- data/test/tools/test_tools.rb +0 -61
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
=begin
|
|
4
4
|
mo.rb - A simple class for operating GNU MO file.
|
|
@@ -43,12 +43,8 @@ module GetText
|
|
|
43
43
|
:trans_sysdep_tab_offset
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde"
|
|
47
|
-
MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95"
|
|
48
|
-
if "".respond_to?(:force_encoding)
|
|
49
|
-
MAGIC_BIG_ENDIAN.force_encoding("ASCII-8BIT")
|
|
50
|
-
MAGIC_LITTLE_ENDIAN.force_encoding("ASCII-8BIT")
|
|
51
|
-
end
|
|
46
|
+
MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde".force_encoding("ASCII-8BIT")
|
|
47
|
+
MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95".force_encoding("ASCII-8BIT")
|
|
52
48
|
|
|
53
49
|
def self.open(arg = nil, output_charset = nil)
|
|
54
50
|
result = self.new(output_charset)
|
|
@@ -312,35 +308,24 @@ module GetText
|
|
|
312
308
|
attr_reader :charset, :nplurals, :plural
|
|
313
309
|
|
|
314
310
|
private
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return string if @output_charset.nil? or @charset.nil?
|
|
311
|
+
def convert_encoding(string, original_string)
|
|
312
|
+
return string if @output_charset.nil? or @charset.nil?
|
|
318
313
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if $DEBUG
|
|
323
|
-
warn "@charset = ", @charset
|
|
324
|
-
warn "@output_charset = ", @output_charset
|
|
325
|
-
warn "msgid = ", original_string
|
|
326
|
-
warn "msgstr = ", string
|
|
327
|
-
end
|
|
328
|
-
string
|
|
329
|
-
end
|
|
314
|
+
if Encoding.find(@output_charset) == Encoding.find(@charset)
|
|
315
|
+
string.force_encoding(@output_charset)
|
|
316
|
+
return string
|
|
330
317
|
end
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
warn "msgid = ", original_string
|
|
341
|
-
warn "msgstr = ", str
|
|
342
|
-
end
|
|
318
|
+
|
|
319
|
+
begin
|
|
320
|
+
string.encode(@output_charset, @charset)
|
|
321
|
+
rescue EncodingError
|
|
322
|
+
if $DEBUG
|
|
323
|
+
warn "@charset = ", @charset
|
|
324
|
+
warn "@output_charset = ", @output_charset
|
|
325
|
+
warn "msgid = ", original_string
|
|
326
|
+
warn "msgstr = ", string
|
|
343
327
|
end
|
|
328
|
+
string
|
|
344
329
|
end
|
|
345
330
|
end
|
|
346
331
|
|
|
@@ -53,9 +53,12 @@ module GetText
|
|
|
53
53
|
|
|
54
54
|
class << self
|
|
55
55
|
def escape(string)
|
|
56
|
-
string.gsub(/([\\"\n])/) do
|
|
56
|
+
string.gsub(/([\\"\t\n])/) do
|
|
57
57
|
special_character = $1
|
|
58
|
-
|
|
58
|
+
case special_character
|
|
59
|
+
when "\t"
|
|
60
|
+
"\\t"
|
|
61
|
+
when "\n"
|
|
59
62
|
"\\n"
|
|
60
63
|
else
|
|
61
64
|
"\\#{special_character}"
|
|
@@ -110,7 +113,8 @@ module GetText
|
|
|
110
113
|
def add_comment(new_comment)
|
|
111
114
|
if (new_comment and ! new_comment.empty?)
|
|
112
115
|
@extracted_comment ||= ""
|
|
113
|
-
@extracted_comment
|
|
116
|
+
@extracted_comment << "\n" unless @extracted_comment.empty?
|
|
117
|
+
@extracted_comment << new_comment
|
|
114
118
|
end
|
|
115
119
|
to_s
|
|
116
120
|
end
|
|
@@ -328,7 +332,7 @@ module GetText
|
|
|
328
332
|
# param is symbol with the name of param
|
|
329
333
|
# value - new value
|
|
330
334
|
def set_value(param, value)
|
|
331
|
-
send "#{param}=", (send(param) || '') + value
|
|
335
|
+
send "#{param}=", (send(param) || '') + value
|
|
332
336
|
end
|
|
333
337
|
|
|
334
338
|
def escape(value)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
#
|
|
3
|
-
#
|
|
3
|
+
# po_parser.rb - Generate a .mo
|
|
4
4
|
#
|
|
5
5
|
# Copyright (C) 2003-2009 Masao Mutoh <mutomasa at gmail.com>
|
|
6
6
|
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
|
@@ -16,21 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
require 'racc/parser.rb'
|
|
18
18
|
|
|
19
|
-
require "gettext/
|
|
19
|
+
require "gettext/po"
|
|
20
20
|
|
|
21
|
-
# For suppressing warning. PoData is deprecated and will be removed.
|
|
22
|
-
module GetText
|
|
23
|
-
module Tools
|
|
24
|
-
class MsgMerge
|
|
25
|
-
class PoData
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
21
|
module GetText
|
|
31
22
|
class POParser < Racc::Parser
|
|
32
23
|
|
|
33
|
-
module_eval(<<'...end
|
|
24
|
+
module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
34
25
|
if GetText.respond_to?(:bindtextdomain)
|
|
35
26
|
include GetText
|
|
36
27
|
GetText.bindtextdomain("gettext")
|
|
@@ -121,7 +112,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
121
112
|
str = str[1..-1]
|
|
122
113
|
end
|
|
123
114
|
end
|
|
124
|
-
@q.push [false,
|
|
115
|
+
@q.push [false, "$end"]
|
|
125
116
|
if $DEBUG
|
|
126
117
|
@q.each do |a,b|
|
|
127
118
|
puts "[#{a}, #{b}]"
|
|
@@ -143,8 +134,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
143
134
|
def on_message(msgid, msgstr)
|
|
144
135
|
msgstr = nil if msgstr.empty?
|
|
145
136
|
|
|
146
|
-
if @data.instance_of?(PO)
|
|
147
|
-
@data.instance_of?(GetText::Tools::MsgMerge::PoData)
|
|
137
|
+
if @data.instance_of?(PO)
|
|
148
138
|
type = detect_entry_type
|
|
149
139
|
entry = POEntry.new(type)
|
|
150
140
|
entry.translator_comment = format_comment(@translator_comments)
|
|
@@ -157,15 +147,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
157
147
|
entry.msgid_plural = @msgid_plural
|
|
158
148
|
entry.msgstr = msgstr
|
|
159
149
|
|
|
160
|
-
|
|
161
|
-
@data[@msgctxt, msgid] = entry
|
|
162
|
-
elsif @data.instance_of?(GetText::Tools::MsgMerge::PoData)
|
|
163
|
-
id = ""
|
|
164
|
-
id << "#{@msgctxt}\004" unless @msgctxt.nil?
|
|
165
|
-
id << msgid
|
|
166
|
-
id << "\000#{@msgid_plural}" unless @msgid_plural.nil?
|
|
167
|
-
@data[id] = entry
|
|
168
|
-
end
|
|
150
|
+
@data[@msgctxt, msgid] = entry
|
|
169
151
|
else
|
|
170
152
|
options = {}
|
|
171
153
|
options[:msgctxt] = @msgctxt
|
|
@@ -195,8 +177,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
195
177
|
|
|
196
178
|
def on_comment(comment)
|
|
197
179
|
@fuzzy = true if (/fuzzy/ =~ comment)
|
|
198
|
-
if @data.instance_of?(PO)
|
|
199
|
-
@data.instance_of?(GetText::Tools::MsgMerge::PoData)
|
|
180
|
+
if @data.instance_of?(PO)
|
|
200
181
|
if comment == "#"
|
|
201
182
|
@translator_comments << ""
|
|
202
183
|
elsif /\A(#.)\s*(.*)\z/ =~ comment
|
|
@@ -208,7 +189,7 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
208
189
|
when POEntry::EXTRACTED_COMMENT_MARK
|
|
209
190
|
@extracted_comments << content
|
|
210
191
|
when POEntry::REFERENCE_COMMENT_MARK
|
|
211
|
-
@references
|
|
192
|
+
@references.concat(parse_references_line(content))
|
|
212
193
|
when POEntry::FLAG_MARK
|
|
213
194
|
@flag << content
|
|
214
195
|
when POEntry::PREVIOUS_COMMENT_MARK
|
|
@@ -233,15 +214,31 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
233
214
|
parse(File.open(*args) {|io| io.read }, data)
|
|
234
215
|
end
|
|
235
216
|
|
|
217
|
+
private
|
|
236
218
|
def detect_file_encoding(po_file)
|
|
237
|
-
open(po_file, :encoding =>
|
|
219
|
+
open(po_file, :encoding => "ASCII-8BIT") do |input|
|
|
220
|
+
in_header = false
|
|
238
221
|
input.each_line do |line|
|
|
239
|
-
|
|
222
|
+
case line.chomp
|
|
223
|
+
when /\Amsgid\s+"(.*)"\z/
|
|
224
|
+
id = $1
|
|
225
|
+
break unless id.empty?
|
|
226
|
+
in_header = true
|
|
227
|
+
when /\A"Content-Type:.*\scharset=(.*)\\n"\z/
|
|
228
|
+
charset = $1
|
|
229
|
+
next unless in_header
|
|
230
|
+
break if template_charset?(charset)
|
|
231
|
+
return Encoding.find(charset)
|
|
232
|
+
end
|
|
240
233
|
end
|
|
241
234
|
end
|
|
242
235
|
Encoding.default_external
|
|
243
236
|
end
|
|
244
237
|
|
|
238
|
+
def template_charset?(charset)
|
|
239
|
+
charset == "CHARSET"
|
|
240
|
+
end
|
|
241
|
+
|
|
245
242
|
def detect_entry_type
|
|
246
243
|
if @msgctxt.nil?
|
|
247
244
|
if @msgid_plural.nil?
|
|
@@ -257,8 +254,11 @@ module_eval(<<'...end poparser.ry/module_eval...', 'poparser.ry', 132)
|
|
|
257
254
|
end
|
|
258
255
|
end
|
|
259
256
|
end
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
|
|
258
|
+
def parse_references_line(line)
|
|
259
|
+
line.split(/\s+/)
|
|
260
|
+
end
|
|
261
|
+
...end po_parser.ry/module_eval...
|
|
262
262
|
##### State transition tables begin ###
|
|
263
263
|
|
|
264
264
|
racc_action_table = [
|
|
@@ -381,7 +381,7 @@ Racc_debug_parser = true
|
|
|
381
381
|
|
|
382
382
|
# reduce 4 omitted
|
|
383
383
|
|
|
384
|
-
module_eval(<<'.,.,', '
|
|
384
|
+
module_eval(<<'.,.,', 'po_parser.ry', 26)
|
|
385
385
|
def _reduce_5(val, _values, result)
|
|
386
386
|
@msgctxt = unescape(val[1])
|
|
387
387
|
|
|
@@ -393,7 +393,7 @@ module_eval(<<'.,.,', 'poparser.ry', 26)
|
|
|
393
393
|
|
|
394
394
|
# reduce 7 omitted
|
|
395
395
|
|
|
396
|
-
module_eval(<<'.,.,', '
|
|
396
|
+
module_eval(<<'.,.,', 'po_parser.ry', 38)
|
|
397
397
|
def _reduce_8(val, _values, result)
|
|
398
398
|
msgid_raw = val[1]
|
|
399
399
|
msgid = unescape(msgid_raw)
|
|
@@ -418,7 +418,7 @@ module_eval(<<'.,.,', 'poparser.ry', 38)
|
|
|
418
418
|
end
|
|
419
419
|
.,.,
|
|
420
420
|
|
|
421
|
-
module_eval(<<'.,.,', '
|
|
421
|
+
module_eval(<<'.,.,', 'po_parser.ry', 61)
|
|
422
422
|
def _reduce_9(val, _values, result)
|
|
423
423
|
if @fuzzy and ignore_fuzzy?
|
|
424
424
|
if val[1] != ""
|
|
@@ -427,7 +427,7 @@ module_eval(<<'.,.,', 'poparser.ry', 61)
|
|
|
427
427
|
$stderr.print "msgid = '#{val[1]}\n"
|
|
428
428
|
end
|
|
429
429
|
else
|
|
430
|
-
on_message(
|
|
430
|
+
on_message("", unescape(val[3]))
|
|
431
431
|
end
|
|
432
432
|
@fuzzy = false
|
|
433
433
|
else
|
|
@@ -440,7 +440,7 @@ module_eval(<<'.,.,', 'poparser.ry', 61)
|
|
|
440
440
|
end
|
|
441
441
|
.,.,
|
|
442
442
|
|
|
443
|
-
module_eval(<<'.,.,', '
|
|
443
|
+
module_eval(<<'.,.,', 'po_parser.ry', 82)
|
|
444
444
|
def _reduce_10(val, _values, result)
|
|
445
445
|
if val[0].size > 0
|
|
446
446
|
result = val[0] + "\000" + val[1]
|
|
@@ -454,7 +454,7 @@ module_eval(<<'.,.,', 'poparser.ry', 82)
|
|
|
454
454
|
|
|
455
455
|
# reduce 11 omitted
|
|
456
456
|
|
|
457
|
-
module_eval(<<'.,.,', '
|
|
457
|
+
module_eval(<<'.,.,', 'po_parser.ry', 94)
|
|
458
458
|
def _reduce_12(val, _values, result)
|
|
459
459
|
result = val[2]
|
|
460
460
|
|
|
@@ -462,7 +462,7 @@ module_eval(<<'.,.,', 'poparser.ry', 94)
|
|
|
462
462
|
end
|
|
463
463
|
.,.,
|
|
464
464
|
|
|
465
|
-
module_eval(<<'.,.,', '
|
|
465
|
+
module_eval(<<'.,.,', 'po_parser.ry', 101)
|
|
466
466
|
def _reduce_13(val, _values, result)
|
|
467
467
|
on_comment(val[0])
|
|
468
468
|
|
|
@@ -470,7 +470,7 @@ module_eval(<<'.,.,', 'poparser.ry', 101)
|
|
|
470
470
|
end
|
|
471
471
|
.,.,
|
|
472
472
|
|
|
473
|
-
module_eval(<<'.,.,', '
|
|
473
|
+
module_eval(<<'.,.,', 'po_parser.ry', 109)
|
|
474
474
|
def _reduce_14(val, _values, result)
|
|
475
475
|
result = val.delete_if{|item| item == ""}.join
|
|
476
476
|
|
|
@@ -478,7 +478,7 @@ module_eval(<<'.,.,', 'poparser.ry', 109)
|
|
|
478
478
|
end
|
|
479
479
|
.,.,
|
|
480
480
|
|
|
481
|
-
module_eval(<<'.,.,', '
|
|
481
|
+
module_eval(<<'.,.,', 'po_parser.ry', 113)
|
|
482
482
|
def _reduce_15(val, _values, result)
|
|
483
483
|
result = val[0]
|
|
484
484
|
|
|
@@ -493,7 +493,4 @@ end
|
|
|
493
493
|
end # class POParser
|
|
494
494
|
end # module GetText
|
|
495
495
|
|
|
496
|
-
|
|
497
|
-
module GetText
|
|
498
|
-
PoParser = POParser
|
|
499
|
-
end
|
|
496
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
=begin
|
|
4
|
-
|
|
4
|
+
text_domain.rb - GetText::TextDomain
|
|
5
5
|
|
|
6
6
|
Copyright (C) 2001-2009 Masao Mutoh
|
|
7
7
|
Copyright (C) 2001-2003 Masahiro Sakai
|
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
license terms as Ruby or LGPL.
|
|
14
14
|
=end
|
|
15
15
|
|
|
16
|
-
require 'gettext/
|
|
17
|
-
require 'gettext/
|
|
18
|
-
require 'gettext/runtime/locale_path'
|
|
16
|
+
require 'gettext/mo'
|
|
17
|
+
require 'gettext/locale_path'
|
|
19
18
|
|
|
20
19
|
module GetText
|
|
21
|
-
# GetText::TextDomain class manages mo-files of a
|
|
20
|
+
# GetText::TextDomain class manages mo-files of a text domain.
|
|
22
21
|
#
|
|
23
22
|
# Usually, you don't need to use this class directly.
|
|
24
23
|
#
|
|
@@ -42,17 +41,8 @@ module GetText
|
|
|
42
41
|
@@cached = val
|
|
43
42
|
end
|
|
44
43
|
|
|
45
|
-
# Add default locale path. Usually you should use GetText.add_default_locale_path instead.
|
|
46
|
-
# * path: a new locale path. (e.g.) "/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
|
|
47
|
-
# ('locale' => "ja_JP", 'name' => "textdomain")
|
|
48
|
-
# * Returns: the new DEFAULT_LOCALE_PATHS
|
|
49
|
-
def self.add_default_locale_path(path)
|
|
50
|
-
warn "Deprecated. Use GetText::LocalePath.add_default_rule instead."
|
|
51
|
-
LocalePath.add_default_rule(path)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
44
|
# Creates a new GetText::TextDomain.
|
|
55
|
-
# * name: the
|
|
45
|
+
# * name: the text domain name.
|
|
56
46
|
# * topdir: the locale path ("%{topdir}/%{lang}/LC_MESSAGES/%{name}.mo") or nil.
|
|
57
47
|
# * output_charset: output charset.
|
|
58
48
|
# * Returns: a newly created GetText::TextDomain object.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
gettext/text_domain_group - GetText::TextDomainGroup class
|
|
5
|
+
|
|
6
|
+
Copyright (C) 2009 Masao Mutoh
|
|
7
|
+
|
|
8
|
+
You may redistribute it and/or modify it under the same
|
|
9
|
+
license terms as Ruby or LGPL.
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module GetText
|
|
14
|
+
|
|
15
|
+
class TextDomainGroup
|
|
16
|
+
attr_reader :text_domains
|
|
17
|
+
|
|
18
|
+
def initialize
|
|
19
|
+
@text_domains = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add(text_domain)
|
|
23
|
+
@text_domains.unshift(text_domain) unless @text_domains.include? text_domain
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
=begin
|
|
4
|
-
gettext/
|
|
4
|
+
gettext/text_domain_manager - GetText::TextDomainManager class
|
|
5
5
|
|
|
6
6
|
Copyright (C) 2009 Masao Mutoh
|
|
7
7
|
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
=end
|
|
12
12
|
|
|
13
|
-
require 'gettext/
|
|
14
|
-
require 'gettext/
|
|
15
|
-
require 'gettext/
|
|
13
|
+
require 'gettext/class_info'
|
|
14
|
+
require 'gettext/text_domain'
|
|
15
|
+
require 'gettext/text_domain_group'
|
|
16
16
|
|
|
17
17
|
module GetText
|
|
18
18
|
|
|
19
19
|
module TextDomainManager
|
|
20
20
|
|
|
21
|
-
@@
|
|
22
|
-
@@
|
|
21
|
+
@@text_domain_pool = {}
|
|
22
|
+
@@text_domain_group_pool = {}
|
|
23
23
|
|
|
24
24
|
@@output_charset = nil
|
|
25
25
|
@@gettext_classes = []
|
|
@@ -30,9 +30,9 @@ module GetText
|
|
|
30
30
|
|
|
31
31
|
extend self
|
|
32
32
|
|
|
33
|
-
# Find
|
|
34
|
-
def
|
|
35
|
-
@@
|
|
33
|
+
# Find text domain by name
|
|
34
|
+
def text_domain_pool(domainname)
|
|
35
|
+
@@text_domain_pool[domainname]
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Set the value whether cache messages or not.
|
|
@@ -58,30 +58,30 @@ module GetText
|
|
|
58
58
|
# Sets the output charset.The program can have a output charset.
|
|
59
59
|
def output_charset=(charset)
|
|
60
60
|
@@output_charset = charset
|
|
61
|
-
@@
|
|
62
|
-
|
|
61
|
+
@@text_domain_pool.each do |key, text_domain|
|
|
62
|
+
text_domain.output_charset = charset
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# bind
|
|
66
|
+
# bind text domain to the class.
|
|
67
67
|
def bind_to(klass, domainname, options = {})
|
|
68
68
|
warn "Bind the domain '#{domainname}' to '#{klass}'. " if $DEBUG
|
|
69
69
|
|
|
70
70
|
charset = options[:output_charset] || self.output_charset
|
|
71
|
-
|
|
71
|
+
text_domain = create_or_find_text_domain(domainname,options[:path],charset)
|
|
72
72
|
target_klass = ClassInfo.normalize_class(klass)
|
|
73
|
-
|
|
73
|
+
create_or_find_text_domain_group(target_klass).add(text_domain)
|
|
74
74
|
@@gettext_classes << target_klass unless @@gettext_classes.include? target_klass
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
text_domain
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
def
|
|
79
|
+
def each_text_domains(klass) #:nodoc:
|
|
80
80
|
lang = Locale.candidates[0]
|
|
81
81
|
ClassInfo.related_classes(klass, @@gettext_classes).each do |target|
|
|
82
|
-
if group = @@
|
|
83
|
-
group.
|
|
84
|
-
yield
|
|
82
|
+
if group = @@text_domain_group_pool[target]
|
|
83
|
+
group.text_domains.each do |text_domain|
|
|
84
|
+
yield text_domain, lang
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
end
|
|
@@ -100,8 +100,8 @@ module GetText
|
|
|
100
100
|
msg = @@singular_message_cache[key]
|
|
101
101
|
return msg if msg and @@cached
|
|
102
102
|
# Find messages from related classes.
|
|
103
|
-
|
|
104
|
-
msg =
|
|
103
|
+
each_text_domains(klass) do |text_domain, lang|
|
|
104
|
+
msg = text_domain.translate_singular_message(lang, msgid)
|
|
105
105
|
break if msg
|
|
106
106
|
end
|
|
107
107
|
|
|
@@ -161,8 +161,8 @@ module GetText
|
|
|
161
161
|
unless (msgs and @@cached)
|
|
162
162
|
# Find messages from related classes.
|
|
163
163
|
msgs = nil
|
|
164
|
-
|
|
165
|
-
msgs =
|
|
164
|
+
each_text_domains(klass) do |text_domain, lang|
|
|
165
|
+
msgs = text_domain.translate_plural_message(lang, msgid, msgid_plural)
|
|
166
166
|
break if msgs
|
|
167
167
|
end
|
|
168
168
|
|
|
@@ -183,25 +183,25 @@ module GetText
|
|
|
183
183
|
end
|
|
184
184
|
|
|
185
185
|
# for testing.
|
|
186
|
-
def
|
|
186
|
+
def dump_all_text_domains
|
|
187
187
|
[
|
|
188
|
-
@@
|
|
189
|
-
@@
|
|
188
|
+
@@text_domain_pool.dup,
|
|
189
|
+
@@text_domain_group_pool.dup,
|
|
190
190
|
@@gettext_classes.dup,
|
|
191
191
|
]
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
# for testing.
|
|
195
|
-
def
|
|
196
|
-
@@
|
|
197
|
-
|
|
195
|
+
def restore_all_text_domains(dumped_all_text_domains)
|
|
196
|
+
@@text_domain_pool, @@text_domain_group_pool, @@gettext_classes =
|
|
197
|
+
dumped_all_text_domains
|
|
198
198
|
clear_caches
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
# for testing.
|
|
202
|
-
def
|
|
203
|
-
@@
|
|
204
|
-
@@
|
|
202
|
+
def clear_all_text_domains
|
|
203
|
+
@@text_domain_pool = {}
|
|
204
|
+
@@text_domain_group_pool = {}
|
|
205
205
|
@@gettext_classes = []
|
|
206
206
|
clear_caches
|
|
207
207
|
end
|
|
@@ -212,18 +212,18 @@ module GetText
|
|
|
212
212
|
@@plural_message_cache = {}
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
-
def
|
|
216
|
-
group = @@
|
|
215
|
+
def create_or_find_text_domain_group(klass) #:nodoc:
|
|
216
|
+
group = @@text_domain_group_pool[klass]
|
|
217
217
|
return group if group
|
|
218
218
|
|
|
219
|
-
@@
|
|
219
|
+
@@text_domain_group_pool[klass] = TextDomainGroup.new
|
|
220
220
|
end
|
|
221
221
|
|
|
222
|
-
def
|
|
223
|
-
|
|
224
|
-
return
|
|
222
|
+
def create_or_find_text_domain(name, path, charset)#:nodoc:
|
|
223
|
+
text_domain = @@text_domain_pool[name]
|
|
224
|
+
return text_domain if text_domain
|
|
225
225
|
|
|
226
|
-
@@
|
|
226
|
+
@@text_domain_pool[name] = TextDomain.new(name, path, charset)
|
|
227
227
|
end
|
|
228
228
|
end
|
|
229
229
|
end
|