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.
Files changed (106) hide show
  1. data/.yardopts +1 -0
  2. data/README.rdoc +28 -23
  3. data/Rakefile +29 -21
  4. data/doc/text/news.md +57 -0
  5. data/gettext.gemspec +1 -1
  6. data/lib/gettext.rb +13 -29
  7. data/lib/gettext/cgi.rb +1 -1
  8. data/lib/gettext/{runtime/class_info.rb → class_info.rb} +1 -1
  9. data/lib/gettext/{runtime/locale_path.rb → locale_path.rb} +1 -2
  10. data/lib/gettext/{runtime/mo.rb → mo.rb} +18 -33
  11. data/lib/gettext/{tools/po.rb → po.rb} +1 -1
  12. data/lib/gettext/{tools/po_entry.rb → po_entry.rb} +8 -4
  13. data/lib/gettext/{tools/poparser.rb → po_parser.rb} +41 -44
  14. data/lib/gettext/{runtime/textdomain.rb → text_domain.rb} +6 -16
  15. data/lib/gettext/text_domain_group.rb +26 -0
  16. data/lib/gettext/{runtime/textdomain_manager.rb → text_domain_manager.rb} +40 -40
  17. data/lib/gettext/tools.rb +1 -182
  18. data/lib/gettext/tools/msgfmt.rb +1 -1
  19. data/lib/gettext/tools/msginit.rb +1 -1
  20. data/lib/gettext/tools/msgmerge.rb +2 -221
  21. data/lib/gettext/tools/parser/erb.rb +49 -30
  22. data/lib/gettext/tools/parser/glade.rb +44 -36
  23. data/lib/gettext/tools/parser/ruby.rb +126 -37
  24. data/lib/gettext/tools/task.rb +225 -0
  25. data/lib/gettext/tools/xgettext.rb +25 -28
  26. data/lib/gettext/version.rb +1 -1
  27. data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
  28. data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
  29. data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
  30. data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
  31. data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  32. data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  33. data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
  34. data/locale/es/LC_MESSAGES/gettext.mo +0 -0
  35. data/locale/et/LC_MESSAGES/gettext.mo +0 -0
  36. data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
  37. data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
  38. data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
  39. data/locale/it/LC_MESSAGES/gettext.mo +0 -0
  40. data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
  41. data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
  42. data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
  43. data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
  44. data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
  45. data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
  46. data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
  47. data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  48. data/locale/sv/LC_MESSAGES/gettext.mo +0 -0
  49. data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  50. data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
  51. data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
  52. data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
  53. data/po/gettext.pot +171 -97
  54. data/samples/hello.rb +3 -2
  55. data/samples/hello2.rb +2 -1
  56. data/samples/hello_gtk2.rb +4 -1
  57. data/samples/hello_gtk_builder.rb +32 -0
  58. data/samples/hello_gtk_builder.ui +46 -0
  59. data/samples/hello_noop.rb +2 -1
  60. data/samples/hello_plural.rb +2 -1
  61. data/samples/hello_tk.rb +2 -1
  62. data/src/{poparser.ry → po_parser.ry} +31 -35
  63. data/test/fixtures/N_.rb +1 -1
  64. data/test/fixtures/_/double_quote_in_double_quote.rb +32 -0
  65. data/test/fixtures/_/double_quote_in_single_quote.rb +32 -0
  66. data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +36 -0
  67. data/test/fixtures/_/middle_new_line.rb +32 -0
  68. data/test/fixtures/_/multiple_lines_literal.rb +35 -0
  69. data/test/fixtures/_/multiple_messages_in_same_line.rb +32 -0
  70. data/test/fixtures/_/multiple_same_messages.rb +36 -0
  71. data/{lib/gettext/runtime/mofile.rb → test/fixtures/_/one_new_line.rb} +12 -6
  72. data/test/fixtures/{multi_textdomain.rb → multi_text_domain.rb} +1 -1
  73. data/test/fixtures/non_ascii.rb +1 -1
  74. data/test/fixtures/simple.rb +1 -1
  75. data/test/fixtures/untranslated.rb +1 -1
  76. data/test/gettext-test-utils.rb +1 -24
  77. data/test/po/ja/_.po +63 -13
  78. data/test/po/ja/non_ascii.po +2 -3
  79. data/test/po/ja/untranslated.po +1 -1
  80. data/test/test_class_info.rb +2 -2
  81. data/test/test_gettext.rb +11 -11
  82. data/test/test_mo.rb +2 -2
  83. data/test/test_parser.rb +93 -96
  84. data/test/test_po_entry.rb +237 -146
  85. data/test/test_po_parser.rb +107 -98
  86. data/test/test_string.rb +1 -1
  87. data/test/{test_textdomain_bind.rb → test_text_domain_bind.rb} +6 -6
  88. data/test/{test_textdomain_multi.rb → test_text_domain_multi.rb} +5 -5
  89. data/test/{test_textdomain_toplevel.rb → test_text_domain_toplevel.rb} +1 -1
  90. data/test/test_thread.rb +1 -1
  91. data/test/tools/files/simple_translation.rb +1 -1
  92. data/test/{parser → tools/parser}/test_ruby.rb +110 -14
  93. data/test/tools/test_msgmerge.rb +17 -276
  94. data/test/tools/test_po.rb +1 -1
  95. data/test/tools/test_xgettext.rb +175 -144
  96. metadata +59 -33
  97. data/lib/gettext/core_ext/iconv.rb +0 -110
  98. data/lib/gettext/core_ext/string.rb +0 -91
  99. data/lib/gettext/parser/erb.rb +0 -5
  100. data/lib/gettext/parser/glade.rb +0 -5
  101. data/lib/gettext/parser/ruby.rb +0 -172
  102. data/lib/gettext/runtime/textdomain_group.rb +0 -26
  103. data/lib/gettext/task.rb +0 -203
  104. data/lib/gettext/utils.rb +0 -39
  105. data/test/test_po_generation.rb +0 -45
  106. data/test/tools/test_tools.rb +0 -61
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- if "".respond_to?(:encode)
316
- def convert_encoding(string, original_string)
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
- 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
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
- else
332
- require 'gettext/core_ext/iconv'
333
- def convert_encoding(string, original_string)
334
- begin
335
- Iconv.conv(@output_charset, @charset, string)
336
- rescue Iconv::Failure
337
- if $DEBUG
338
- warn "@charset = ", @charset
339
- warn "@output_charset = ", @output_charset
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
 
@@ -17,7 +17,7 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "gettext/tools/po_entry"
20
+ require "gettext/po_entry"
21
21
 
22
22
  module GetText
23
23
 
@@ -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
- if special_character == "\n"
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 += new_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.gsub(/\n/, '\n')
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
- # poparser.rb - Generate a .mo
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/tools/po"
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 poparser.ry/module_eval...', 'poparser.ry', 132)
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, '$end']
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) or
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
- if @data.instance_of?(PO)
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) or
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 << content
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 => 'ASCII-8BIT') do |input|
219
+ open(po_file, :encoding => "ASCII-8BIT") do |input|
220
+ in_header = false
238
221
  input.each_line do |line|
239
- return Encoding.find($1) if %r["Content-Type:.*\scharset=(.*)\\n"] =~ line
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
- private :detect_file_encoding
261
- ...end poparser.ry/module_eval...
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(<<'.,.,', 'poparser.ry', 26)
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(<<'.,.,', 'poparser.ry', 38)
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(<<'.,.,', 'poparser.ry', 61)
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('', unescape(val[3]))
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(<<'.,.,', 'poparser.ry', 82)
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(<<'.,.,', 'poparser.ry', 94)
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(<<'.,.,', 'poparser.ry', 101)
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(<<'.,.,', 'poparser.ry', 109)
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(<<'.,.,', 'poparser.ry', 113)
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
- # for backward compatibility.
497
- module GetText
498
- PoParser = POParser
499
- end
496
+
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  =begin
4
- textdomain.rb - GetText::Textdomain
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/core_ext/string'
17
- require 'gettext/runtime/mo'
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 textdomain.
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 textdomain name.
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
- # encoding: utf-8
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  =begin
4
- gettext/textdomain_manager - GetText::TextDomainManager class
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/runtime/class_info'
14
- require 'gettext/runtime/textdomain'
15
- require 'gettext/runtime/textdomain_group'
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
- @@textdomain_pool = {}
22
- @@textdomain_group_pool = {}
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 textdomain by name
34
- def textdomain_pool(domainname)
35
- @@textdomain_pool[domainname]
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
- @@textdomain_pool.each do |key, textdomain|
62
- textdomain.output_charset = charset
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 textdomain to the class.
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
- textdomain = create_or_find_textdomain(domainname,options[:path],charset)
71
+ text_domain = create_or_find_text_domain(domainname,options[:path],charset)
72
72
  target_klass = ClassInfo.normalize_class(klass)
73
- create_or_find_textdomain_group(target_klass).add(textdomain)
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
- textdomain
76
+ text_domain
77
77
  end
78
78
 
79
- def each_textdomains(klass) #:nodoc:
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 = @@textdomain_group_pool[target]
83
- group.textdomains.each do |textdomain|
84
- yield textdomain, lang
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
- each_textdomains(klass) do |textdomain, lang|
104
- msg = textdomain.translate_singular_message(lang, msgid)
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
- each_textdomains(klass) do |textdomain, lang|
165
- msgs = textdomain.translate_plural_message(lang, msgid, msgid_plural)
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 dump_all_textdomains
186
+ def dump_all_text_domains
187
187
  [
188
- @@textdomain_pool.dup,
189
- @@textdomain_group_pool.dup,
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 restore_all_textdomains(dumped_all_textdomains)
196
- @@textdomain_pool, @@textdomain_group_pool, @@gettext_classes =
197
- dumped_all_textdomains
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 clear_all_textdomains
203
- @@textdomain_pool = {}
204
- @@textdomain_group_pool = {}
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 create_or_find_textdomain_group(klass) #:nodoc:
216
- group = @@textdomain_group_pool[klass]
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
- @@textdomain_group_pool[klass] = TextDomainGroup.new
219
+ @@text_domain_group_pool[klass] = TextDomainGroup.new
220
220
  end
221
221
 
222
- def create_or_find_textdomain(name, path, charset)#:nodoc:
223
- textdomain = @@textdomain_pool[name]
224
- return textdomain if textdomain
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
- @@textdomain_pool[name] = TextDomain.new(name, path, charset)
226
+ @@text_domain_pool[name] = TextDomain.new(name, path, charset)
227
227
  end
228
228
  end
229
229
  end