gettext 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/ChangeLog +128 -0
  2. data/NEWS +10 -0
  3. data/README +21 -23
  4. data/Rakefile +39 -20
  5. data/bin/rgettext +1 -1
  6. data/bin/rmsgfmt +1 -1
  7. data/bin/rmsgmerge +1 -1
  8. data/data/locale/cs/LC_MESSAGES/rails.mo +0 -0
  9. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  10. data/data/locale/de/LC_MESSAGES/rails.mo +0 -0
  11. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  12. data/data/locale/el/LC_MESSAGES/rails.mo +0 -0
  13. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/es/LC_MESSAGES/rails.mo +0 -0
  15. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/fr/LC_MESSAGES/rails.mo +0 -0
  17. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  18. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/ja/LC_MESSAGES/rails.mo +0 -0
  20. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/ko/LC_MESSAGES/rails.mo +0 -0
  22. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/nl/LC_MESSAGES/rails.mo +0 -0
  24. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/pt_BR/LC_MESSAGES/rails.mo +0 -0
  26. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  28. data/ext/gettext/extconf.rb +20 -0
  29. data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
  30. data/lib/gettext.rb +186 -38
  31. data/lib/gettext/cgi.rb +35 -69
  32. data/lib/gettext/container.rb +14 -5
  33. data/lib/gettext/erb.rb +30 -2
  34. data/lib/gettext/iconv.rb +19 -4
  35. data/lib/gettext/locale.rb +188 -39
  36. data/lib/gettext/locale_cgi.rb +102 -0
  37. data/lib/gettext/locale_object.rb +131 -0
  38. data/lib/gettext/locale_posix.rb +50 -0
  39. data/lib/gettext/locale_table_win32.rb +224 -182
  40. data/lib/gettext/locale_win32.rb +59 -35
  41. data/lib/gettext/mo.rb +2 -2
  42. data/lib/gettext/parser/activerecord.rb +19 -5
  43. data/lib/gettext/parser/erb.rb +6 -3
  44. data/lib/gettext/parser/glade.rb +5 -5
  45. data/lib/gettext/parser/ruby.rb +6 -6
  46. data/lib/gettext/poparser.rb +7 -6
  47. data/lib/gettext/rails.rb +122 -44
  48. data/lib/gettext/rgettext.rb +21 -8
  49. data/lib/gettext/rmsgfmt.rb +16 -8
  50. data/lib/gettext/rmsgmerge.rb +172 -50
  51. data/lib/gettext/string.rb +25 -3
  52. data/lib/gettext/textdomain.rb +89 -90
  53. data/lib/gettext/utils.rb +63 -3
  54. data/lib/gettext/version.rb +2 -2
  55. data/pkg/ruby-gettext-package-1.2.0/ext/gettext/extconf.rb +20 -0
  56. data/po/cs/rails.po +28 -28
  57. data/po/cs/rgettext.po +14 -14
  58. data/po/de/rails.po +29 -26
  59. data/po/de/rgettext.po +24 -17
  60. data/po/el/rails.po +26 -26
  61. data/po/el/rgettext.po +18 -15
  62. data/po/es/rails.po +26 -26
  63. data/po/es/rgettext.po +16 -16
  64. data/po/fr/rails.po +27 -27
  65. data/po/fr/rgettext.po +14 -14
  66. data/po/it/rgettext.po +14 -14
  67. data/po/ja/rails.po +24 -24
  68. data/po/ja/rgettext.po +14 -14
  69. data/po/ko/rails.po +24 -24
  70. data/po/ko/rgettext.po +17 -18
  71. data/po/nl/rails.po +27 -27
  72. data/po/nl/rgettext.po +18 -18
  73. data/po/pt_BR/rails.po +26 -26
  74. data/po/pt_BR/rgettext.po +14 -14
  75. data/po/rails.pot +26 -26
  76. data/po/rgettext.pot +14 -14
  77. data/po/sv/rgettext.po +14 -14
  78. data/post-setup.rb +8 -3
  79. data/pre-setup.rb +14 -1
  80. data/samples/cgi/http.rb +2 -1
  81. data/samples/makemo.rb +1 -1
  82. data/samples/rails/app/models/article.rb +15 -1
  83. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  84. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  85. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  86. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  87. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  88. data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.mo +0 -0
  89. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  90. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  91. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  92. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  93. data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
  94. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  95. data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
  96. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  97. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  98. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  99. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  100. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  101. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  102. data/samples/rails/po/blog.pot +1 -1
  103. data/samples/rails/po/cs/blog.po +1 -2
  104. data/samples/rails/po/cs/gettext_plugin.po +1 -1
  105. data/samples/rails/po/de/blog.po +1 -2
  106. data/samples/rails/po/de/gettext_plugin.po +1 -1
  107. data/samples/rails/po/el/blog.po +1 -1
  108. data/samples/rails/po/el/gettext_plugin.po +1 -1
  109. data/samples/rails/po/en/blog.po +1 -1
  110. data/samples/rails/po/es/blog.po +1 -2
  111. data/samples/rails/po/es/gettext_plugin.po +1 -1
  112. data/samples/rails/po/fr/blog.po +1 -1
  113. data/samples/rails/po/fr/gettext_plugin.po +1 -1
  114. data/samples/rails/po/gettext_plugin.pot +1 -1
  115. data/samples/rails/po/ja/blog.po +2 -1
  116. data/samples/rails/po/ja/gettext_plugin.po +1 -1
  117. data/samples/rails/po/ko/blog.po +1 -2
  118. data/samples/rails/po/ko/gettext_plugin.po +1 -1
  119. data/samples/rails/po/nl/blog.po +1 -3
  120. data/samples/rails/po/nl/gettext_plugin.po +1 -1
  121. data/samples/rails/po/pt_BR/blog.po +1 -1
  122. data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
  123. data/setup.rb +799 -574
  124. data/src/poparser.ry +6 -5
  125. data/test/gettext_runner.rb +3 -1
  126. data/test/gettext_test.rb +40 -24
  127. data/test/gettext_test_cgi.rb +60 -6
  128. data/test/gettext_test_locale.rb +136 -0
  129. data/test/gettext_test_parser.rb +12 -12
  130. data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
  131. data/test/po/la/plural_error.po +21 -0
  132. data/test/test.bat +2 -0
  133. data/test/test.sh +2 -4
  134. data/test/{test_rubyparser_n.rb → test_rubyparser_n_.rb} +0 -0
  135. metadata +17 -12
  136. data/ext/gettext/gettext/MANIFEST +0 -3
  137. data/ext/gettext/gettext/extconf.rb +0 -20
  138. data/lib/gettext/locale_default.rb +0 -35
@@ -17,14 +17,14 @@ require 'gettext'
17
17
 
18
18
  module GetText
19
19
 
20
- module RGetText
20
+ module RGetText # :nodoc:
21
21
  extend GetText
22
22
 
23
23
  bindtextdomain("rgettext")
24
24
 
25
25
  # constant values
26
26
  VERSION = GetText::VERSION
27
- DATE = %w($Date: 2005/12/25 11:43:20 $)[1]
27
+ DATE = %w($Date: 2006/02/22 16:42:41 $)[1]
28
28
  MAX_LINE_LEN = 70
29
29
 
30
30
  @ex_parsers = []
@@ -46,7 +46,7 @@ module GetText
46
46
 
47
47
  module_function
48
48
 
49
- def generate_pot_header
49
+ def generate_pot_header # :nodoc:
50
50
  time = Time.now.strftime("%Y-%m-%d %H:%M")
51
51
  off = Time.now.utc_offset
52
52
  sign = off <= 0 ? '-' : '+'
@@ -71,7 +71,7 @@ msgstr ""
71
71
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"]
72
72
  end
73
73
 
74
- def generate_pot(ary)
74
+ def generate_pot(ary) # :nodoc:
75
75
  str = ""
76
76
  result = Array.new
77
77
  ary.each do |key|
@@ -102,7 +102,7 @@ msgstr ""
102
102
  str
103
103
  end
104
104
 
105
- def parse(files)
105
+ def parse(files) # :nodoc:
106
106
  ary = []
107
107
  files.each do |file|
108
108
  begin
@@ -121,7 +121,7 @@ msgstr ""
121
121
  ary
122
122
  end
123
123
 
124
- def check_options
124
+ def check_options # :nodoc:
125
125
  output = STDOUT
126
126
 
127
127
  opts = OptionParser.new
@@ -155,7 +155,7 @@ msgstr ""
155
155
  [ARGV, output]
156
156
  end
157
157
 
158
- def run(targetfiles = nil, out = STDOUT)
158
+ def run(targetfiles = nil, out = STDOUT) # :nodoc:
159
159
  if targetfiles.is_a? String
160
160
  targetfiles = [targetfiles]
161
161
  elsif ! targetfiles
@@ -175,13 +175,26 @@ msgstr ""
175
175
  out.puts generate_pot_header
176
176
  out.puts generate_pot(parse(targetfiles))
177
177
  end
178
-
178
+ self
179
179
  end
180
180
  end
181
181
 
182
182
  module_function
183
+ # Creates a po-file from targetfiles(ruby-script-files, ActiveRecord, .rhtml files, glade-2 XML files),
184
+ # then output the result to out. If no parameter is set, it behaves same as command line tools(rgettet).
185
+ #
186
+ # This function is a part of GetText.create_pofiles.
187
+ # Usually you don't need to call this function directly.
188
+ #
189
+ # *Note* for ActiveRecord, you need to run your database server and configure the config/database.xml
190
+ # correctly before execute this function.
191
+ #
192
+ # * targetfiles: An Array of po-files or nil.
193
+ # * out: output IO or output path.
194
+ # * Returns: self
183
195
  def rgettext(targetfiles = nil, out = STDOUT)
184
196
  RGetText.run(targetfiles, out)
197
+ self
185
198
  end
186
199
  end
187
200
 
@@ -1,7 +1,7 @@
1
1
  =begin
2
2
  rmsgfmt.rb - Generate a .mo
3
3
 
4
- Copyright (C) 2003-2005 Masao Mutoh <mutoh@highway.ne.jp>
4
+ Copyright (C) 2003-2006 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
@@ -15,14 +15,14 @@ require 'gettext/poparser'
15
15
  module GetText
16
16
  GetText.bindtextdomain("rgettext")
17
17
 
18
- module RMsgfmt
19
- extend GetText
18
+ module RMsgfmt #:nodoc:
19
+ extend GetText
20
20
 
21
- VERSION = GetText::VERSION
22
- DATE = %w($Date: 2005/10/22 10:49:59 $)[1]
21
+ VERSION = GetText::VERSION
22
+ DATE = %w($Date: 2006/02/22 16:42:41 $)[1] # :nodoc:
23
23
 
24
24
  module_function
25
- def run(targetfile = nil, output_path = nil)
25
+ def run(targetfile = nil, output_path = nil) # :nodoc:
26
26
  unless targetfile
27
27
  targetfile, output_path = check_options
28
28
  end
@@ -39,7 +39,7 @@ module GetText
39
39
  data.save_to_file(output_path)
40
40
  end
41
41
 
42
- def check_options
42
+ def check_options # :nodoc:
43
43
  output = nil
44
44
 
45
45
  opts = OptionParser.new
@@ -69,14 +69,21 @@ module GetText
69
69
  end
70
70
 
71
71
  module_function
72
+ # Creates a mo-file from a targetfile(po-file), then output the result to out.
73
+ # If no parameter is set, it behaves same as command line tools(rmsgfmt).
74
+ # * targetfile: An Array of po-files or nil.
75
+ # * output_path: output path.
76
+ # * Returns: the MOFile object.
72
77
  def rmsgfmt(targetfile = nil, output_path = nil)
73
78
  RMsgfmt.run(targetfile, output_path)
74
79
  end
75
80
 
81
+ # Move to gettext/utils.rb. This will be removed in the feature.
82
+ # This remains for backward compatibility. Use gettext/utils.rb instead.
76
83
  def create_mofiles(verbose = false,
77
84
  podir = "./po", targetdir = "./data/locale",
78
85
  targetpath_rule = "%s/LC_MESSAGES")
79
-
86
+ $stderr.puts "This function will be moved to utils.rb. So requires 'utils' first, please."
80
87
  modir = File.join(targetdir, targetpath_rule)
81
88
  Dir.glob(File.join(podir, "*/*.po")) do |file|
82
89
  lang, basename = /\/([^\/]+?)\/(.*)\.po/.match(file[podir.size..-1]).to_a[1,2]
@@ -87,6 +94,7 @@ module GetText
87
94
  $stderr.puts %Q[#{file} -> #{File.join(outdir, "#{basename}.mo")}]
88
95
  end
89
96
  end
97
+ self
90
98
  end
91
99
  end
92
100
 
@@ -1,8 +1,8 @@
1
1
  =begin
2
2
  rmsgmerge.rb - Merge old .po to new .po
3
3
 
4
- Copyright (C) 2005 Masao Mutoh
5
- Copyright (C) 2005 speakillof
4
+ Copyright (C) 2005,2006 Masao Mutoh
5
+ Copyright (C) 2005,2006 speakillof
6
6
 
7
7
  You may redistribute it and/or modify it under the same
8
8
  license terms as Ruby.
@@ -14,9 +14,9 @@ require 'gettext/poparser'
14
14
 
15
15
  module GetText
16
16
 
17
- module RMsgMerge
17
+ module RMsgMerge #:nodoc:
18
18
 
19
- class PoData
19
+ class PoData #:nodoc:
20
20
 
21
21
  attr_reader :msgids
22
22
 
@@ -108,7 +108,10 @@ module GetText
108
108
 
109
109
  def generate_po_entry(msgid)
110
110
  str = ""
111
- str << @msgid2comment[msgid] << "\n"
111
+ str << @msgid2comment[msgid]
112
+ if str[-1] != "\n"[0]
113
+ str << "\n"
114
+ end
112
115
 
113
116
  id = msgid.gsub(/"/, '\"').gsub(/\r/, '')
114
117
  msgstr = @msgid2msgstr[msgid].gsub(/"/, '\"').gsub(/\r/, '')
@@ -134,12 +137,12 @@ module GetText
134
137
 
135
138
  def __conv(str)
136
139
  s = ''
137
-
140
+
138
141
  if str.count("\n") > 1
139
142
  s << '""' << "\n"
140
143
  s << str.gsub(/^(.*)$/, '"\1\n"')
141
144
  else
142
- s << str.gsub(/^(.*)$/, '"\1\n"')
145
+ s << '"' << str.sub("\n", "\\n") << '"'
143
146
  end
144
147
 
145
148
  s.rstrip
@@ -147,20 +150,22 @@ module GetText
147
150
 
148
151
  end
149
152
 
150
- class Merger__
153
+ class Merger #:nodoc:
151
154
 
152
- # From gettext source.
155
+ # From GNU gettext source.
153
156
  #
154
157
  # Merge the reference with the definition: take the #. and
155
158
  # #: comments from the reference, take the # comments from
156
159
  # the definition, take the msgstr from the definition. Add
157
160
  # this merged entry to the output message list.
158
- COMMENT_RE = /\A#\.|\A#\:/
161
+ DOT_COMMENT_RE = /\A#\./
162
+ SEMICOLON_COMMENT_RE = /\A#\:/
163
+ FUZZY_RE = /\A#\,/
164
+ NOT_SPECIAL_COMMENT_RE = /\A#([^:.,]|\z)/
159
165
 
160
166
  CRLF_RE = /\r?\n/
161
-
162
- def initialize
163
- end
167
+ POT_DATE_EXTRACT_RE = /POT-Creation-Date:\s*(.*)?\s*$/
168
+ POT_DATE_RE = /POT-Creation-Date:.*?$/
164
169
 
165
170
  def merge(definition, reference)
166
171
  # deep copy
@@ -168,7 +173,7 @@ module GetText
168
173
 
169
174
  used = []
170
175
  merge_header(result, definition)
171
-
176
+
172
177
  result.each_msgid do |msgid|
173
178
  if definition.msgid?(msgid)
174
179
  used << msgid
@@ -176,11 +181,11 @@ module GetText
176
181
  elsif other_msgid = definition.search_msgid_fuzzy(msgid, used)
177
182
  used << other_msgid
178
183
  merge_fuzzy_message(msgid, result, other_msgid, definition)
184
+ elsif msgid.index("\000") and ( reference.msgstr(msgid).gsub("\000", '') == '' )
185
+ # plural
186
+ result[msgid] = "\000" * definition.nplural
179
187
  else
180
- if msgid.index("\000") and (reference.msgstr(msgid).gsub("\000", '') == '')
181
- #plural
182
- result[msgid] = "\000" * definition.nplural
183
- end
188
+ change_reference_comment(msgid, result)
184
189
  end
185
190
  end
186
191
 
@@ -191,7 +196,7 @@ module GetText
191
196
  definition.each_msgid do |msgid|
192
197
  unless used.include?(msgid)
193
198
  last_comment << "\n"
194
- last_comment << definition.generate_po_entry(msgid).strip.gsub(/^/, '#~ ')
199
+ last_comment << definition.generate_po_entry(msgid).strip.gsub(/^/, '#. ')
195
200
  last_comment << "\n"
196
201
  end
197
202
  end
@@ -237,23 +242,91 @@ module GetText
237
242
  end
238
243
 
239
244
  def merge_comment(msgid, target, def_msgid, definition)
240
- comment = target.comment(msgid)
245
+ ref_comment = target.comment(msgid)
241
246
  def_comment = definition.comment(def_msgid)
242
- new_comment = []
247
+
248
+ normal_comment = []
249
+ dot_comment = []
250
+ semi_comment = []
251
+ is_fuzzy = false
243
252
 
244
253
  def_comment.split(CRLF_RE).each do |l|
245
- unless COMMENT_RE =~ l
246
- new_comment << l
254
+ if NOT_SPECIAL_COMMENT_RE =~ l
255
+ normal_comment << l
247
256
  end
248
257
  end
249
258
 
250
- comment.split(CRLF_RE).each do |l|
251
- if COMMENT_RE =~ l
252
- new_comment << l
259
+ ref_comment.split(CRLF_RE).each do |l|
260
+ if DOT_COMMENT_RE =~ l
261
+ dot_comment << l
262
+ elsif SEMICOLON_COMMENT_RE =~ l
263
+ semi_comment << l
264
+ elsif FUZZY_RE =~ l
265
+ is_fuzzy = true
266
+ end
267
+ end
268
+
269
+ str = format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
270
+ target.set_comment(msgid, str)
271
+ end
272
+
273
+ def change_reference_comment(msgid, podata)
274
+ normal_comment = []
275
+ dot_comment = []
276
+ semi_comment = []
277
+ is_fuzzy = false
278
+
279
+ podata.comment(msgid).split(CRLF_RE).each do |l|
280
+ if DOT_COMMENT_RE =~ l
281
+ dot_comment << l
282
+ elsif SEMICOLON_COMMENT_RE =~ l
283
+ semi_comment << l
284
+ elsif FUZZY_RE =~ l
285
+ is_fuzzy = true
286
+ else
287
+ normal_comment << l
253
288
  end
254
289
  end
255
290
 
256
- target.set_comment(msgid, new_comment.join("\n"))
291
+ str = format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
292
+ podata.set_comment(msgid, str)
293
+ end
294
+
295
+ def format_comment(normal_comment, dot_comment, semi_comment, is_fuzzy)
296
+ str = ''
297
+
298
+ str << normal_comment.join("\n").gsub(/^#(\s*)/){|sss|
299
+ if $1 == ""
300
+ "# "
301
+ else
302
+ sss
303
+ end
304
+ }
305
+ if normal_comment.size > 0
306
+ str << "\n"
307
+ end
308
+
309
+ str << dot_comment.join("\n").gsub(/^#.(\s*)/){|sss|
310
+ if $1 == ""
311
+ "#. "
312
+ else
313
+ sss
314
+ end
315
+ }
316
+ if dot_comment.size > 0
317
+ str << "\n"
318
+ end
319
+
320
+ str << semi_comment.join("\n").gsub(/^#:\s*/, "#: ")
321
+ if semi_comment.size > 0
322
+ str << "\n"
323
+ end
324
+
325
+ if is_fuzzy
326
+ str << "#, fuzzy\n"
327
+ end
328
+
329
+ str
257
330
  end
258
331
 
259
332
  def merge_header(target, definition)
@@ -261,9 +334,9 @@ module GetText
261
334
 
262
335
  msg = target.msgstr('')
263
336
  def_msg = definition.msgstr('')
264
- if /POT-Creation-Date:\s*(.*)?\s*\\n/ =~ msg
337
+ if POT_DATE_EXTRACT_RE =~ msg
265
338
  time = $1
266
- def_msg = def_msg.sub(/POT-Creation-Date:.*\\n/, "POT-Creation-Date: #{time}" + '\n')
339
+ def_msg = def_msg.sub(POT_DATE_RE, "POT-Creation-Date: #{time}")
267
340
  end
268
341
 
269
342
  target[''] = def_msg
@@ -275,11 +348,42 @@ module GetText
275
348
 
276
349
  end
277
350
 
351
+ module GetText::RMsgMerge #:nodoc:
278
352
 
353
+ class Config #:nodoc:
354
+
355
+ attr_accessor :defpo, :refpot, :output, :fuzzy, :update
356
+
357
+ # update mode options
358
+ attr_accessor :backup, :suffix
359
+
360
+ =begin
361
+ The result is written back to def.po.
362
+ --backup=CONTROL make a backup of def.po
363
+ --suffix=SUFFIX override the usual backup suffix
364
+ The version control method may be selected via the --backup option or through
365
+ the VERSION_CONTROL environment variable. Here are the values:
366
+ none, off never make backups (even if --backup is given)
367
+ numbered, t make numbered backups
368
+ existing, nil numbered if numbered backups exist, simple otherwise
369
+ simple, never always make simple backups
370
+ The backup suffix is `~', unless set with --suffix or the SIMPLE_BACKUP_SUFFIX
371
+ environment variable.
372
+ =end
373
+
374
+ def initialize
375
+ @output = STDOUT
376
+ @fuzzy = nil
377
+ @update = nil
378
+ @backup = ENV["VERSION_CONTROL"]
379
+ @suffix= ENV["SIMPLE_BACKUP_SUFFIX"] || "~"
380
+ @input_dirs = ["."]
381
+ end
382
+
383
+ end
384
+
385
+ end
279
386
 
280
- #
281
- # commands
282
- #
283
387
  module GetText
284
388
 
285
389
  module RMsgMerge
@@ -289,15 +393,14 @@ module GetText
289
393
 
290
394
  # constant values
291
395
  VERSION = GetText::VERSION
292
- DATE = %w($Date: 2005/11/27 15:35:55 $)[1]
396
+ DATE = %w($Date: 2006/02/23 14:53:59 $)[1]
293
397
 
294
398
  module_function
295
399
 
296
- def check_options
297
- output = STDOUT
298
-
400
+ def check_options(config)
299
401
  opts = OptionParser.new
300
402
  opts.banner = _("Usage: %s def.po ref.pot [-o output.pot]") % $0
403
+ #opts.summary_width = 80
301
404
  opts.separator("")
302
405
  opts.separator(_("Merges two Uniforum style .po files together. The def.po file is an existing PO file with translations. The ref.pot file is the last created PO file with up-to-date source references. ref.pot is generally created by rgettext."))
303
406
  opts.separator("")
@@ -305,13 +408,15 @@ module GetText
305
408
 
306
409
  opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
307
410
  unless FileTest.exist? out
308
- output = File.new(File.expand_path(out), "w+")
411
+ config.output = out
309
412
  else
310
413
  #$stderr.puts(_("File '%s' has already existed.") % out)
311
414
  #exit 1
312
415
  end
313
416
  end
314
417
 
418
+ #opts.on("-F", "--fuzzy-matching")
419
+
315
420
  opts.on_tail("--version", _("display version information and exit")) do
316
421
  puts "#{$0} #{VERSION} (#{DATE})"
317
422
  exit
@@ -324,27 +429,33 @@ module GetText
324
429
  exit 1
325
430
  end
326
431
 
327
- [ARGV[0], ARGV[1], output]
432
+ config.defpo = ARGV[0]
433
+ config.refpot = ARGV[1]
328
434
  end
329
435
 
330
436
  def run(reference = nil, definition = nil, out = STDOUT)
331
- if reference.nil? or definition.nil?
332
- definition, reference, out = check_options()
333
- end
437
+ config = GetText::RMsgMerge::Config.new
438
+ config.refpot = reference
439
+ config.defpo = definition
440
+ config.output = out
441
+
442
+ check_options(config)
334
443
 
335
- if definition.nil?
444
+ if config.defpo.nil?
336
445
  raise ArgumentError, _("definition po is not given.")
337
- elsif reference.nil?
446
+ elsif config.refpot.nil?
338
447
  raise ArgumentError, _("reference pot is not given.")
339
448
  end
340
449
 
341
450
  parser = PoParser.new
342
- defstr = nil; refstr = nil
343
- File.open(definition){|f| defstr = f.read}; File.open(reference){|f| refstr = f.read}
344
- defpo = parser.parse(defstr, PoData.new)
345
- refpot = parser.parse(refstr, PoData.new)
346
-
347
- m = Merger__.new
451
+ defstr = nil
452
+ refstr = nil
453
+ File.open(config.defpo){|f| defstr = f.read}
454
+ File.open(config.refpot){|f| refstr = f.read}
455
+ defpo = parser.parse(defstr, PoData.new, false)
456
+ refpot = parser.parse(refstr, PoData.new, false)
457
+
458
+ m = Merger.new
348
459
  result = m.merge(defpo, refpot)
349
460
  pp result if $DEBUG
350
461
  print result.generate_po if $DEBUG
@@ -360,16 +471,27 @@ module GetText
360
471
  ensure
361
472
  out.close
362
473
  end
363
- end
474
+ end
475
+
364
476
  end
477
+
478
+ end
365
479
 
480
+
481
+
482
+ module GetText
483
+
366
484
  module_function
485
+
486
+ # Experimental
367
487
  def rmsgmerge(reference = nil, definition = nil, out = STDOUT)
368
488
  RMsgMerge.run(reference, definition, out)
369
489
  end
490
+
370
491
  end
371
492
 
372
493
 
494
+
373
495
  if $0 == __FILE__ then
374
496
  require 'pp'
375
497