gettext 1.1.1-mswin32 → 1.2.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/ChangeLog +128 -0
  2. data/NEWS +10 -0
  3. data/README +21 -23
  4. data/Rakefile +40 -21
  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/{gettext/Makefile → Makefile} +3 -3
  29. data/ext/gettext/extconf.rb +20 -0
  30. data/ext/gettext/locale_system-i386-mswin32.def +2 -0
  31. data/ext/gettext/{gettext/_locale.c → locale_system.c} +15 -19
  32. data/ext/gettext/locale_system.exp +0 -0
  33. data/ext/gettext/locale_system.lib +0 -0
  34. data/ext/gettext/locale_system.obj +0 -0
  35. data/ext/gettext/{gettext/_locale.pdb → locale_system.pdb} +0 -0
  36. data/ext/gettext/locale_system.so +0 -0
  37. data/ext/gettext/mkmf.log +10 -0
  38. data/ext/gettext/{gettext/vc70.pdb → vc70.pdb} +0 -0
  39. data/lib/gettext.rb +186 -38
  40. data/lib/gettext/cgi.rb +35 -69
  41. data/lib/gettext/container.rb +14 -5
  42. data/lib/gettext/erb.rb +30 -2
  43. data/lib/gettext/iconv.rb +19 -4
  44. data/lib/gettext/locale.rb +188 -39
  45. data/lib/gettext/locale_cgi.rb +102 -0
  46. data/lib/gettext/locale_object.rb +131 -0
  47. data/lib/gettext/locale_posix.rb +50 -0
  48. data/lib/gettext/locale_table_win32.rb +224 -182
  49. data/lib/gettext/locale_win32.rb +59 -35
  50. data/lib/gettext/mo.rb +2 -2
  51. data/lib/gettext/parser/activerecord.rb +19 -5
  52. data/lib/gettext/parser/erb.rb +6 -3
  53. data/lib/gettext/parser/glade.rb +5 -5
  54. data/lib/gettext/parser/ruby.rb +6 -6
  55. data/lib/gettext/poparser.rb +298 -297
  56. data/lib/gettext/rails.rb +122 -44
  57. data/lib/gettext/rgettext.rb +21 -8
  58. data/lib/gettext/rmsgfmt.rb +16 -8
  59. data/lib/gettext/rmsgmerge.rb +172 -50
  60. data/lib/gettext/string.rb +25 -3
  61. data/lib/gettext/textdomain.rb +89 -90
  62. data/lib/gettext/utils.rb +63 -3
  63. data/lib/gettext/version.rb +2 -2
  64. data/lib/locale_system.so +0 -0
  65. data/po/cs/rails.po +28 -28
  66. data/po/cs/rgettext.po +14 -14
  67. data/po/de/rails.po +29 -26
  68. data/po/de/rgettext.po +24 -17
  69. data/po/el/rails.po +26 -26
  70. data/po/el/rgettext.po +18 -15
  71. data/po/es/rails.po +26 -26
  72. data/po/es/rgettext.po +16 -16
  73. data/po/fr/rails.po +27 -27
  74. data/po/fr/rgettext.po +14 -14
  75. data/po/it/rgettext.po +14 -14
  76. data/po/ja/rails.po +24 -24
  77. data/po/ja/rgettext.po +14 -14
  78. data/po/ko/rails.po +24 -24
  79. data/po/ko/rgettext.po +17 -18
  80. data/po/nl/rails.po +27 -27
  81. data/po/nl/rgettext.po +18 -18
  82. data/po/pt_BR/rails.po +26 -26
  83. data/po/pt_BR/rgettext.po +14 -14
  84. data/po/rails.pot +26 -26
  85. data/po/rgettext.pot +14 -14
  86. data/po/sv/rgettext.po +14 -14
  87. data/post-setup.rb +8 -3
  88. data/pre-setup.rb +14 -1
  89. data/samples/cgi/http.rb +2 -1
  90. data/samples/makemo.rb +1 -1
  91. data/samples/rails/app/models/article.rb +15 -1
  92. data/samples/rails/config/database.yml +1 -1
  93. data/samples/rails/locale/cs/LC_MESSAGES/blog.mo +0 -0
  94. data/samples/rails/locale/cs/LC_MESSAGES/gettext_plugin.mo +0 -0
  95. data/samples/rails/locale/de/LC_MESSAGES/blog.mo +0 -0
  96. data/samples/rails/locale/de/LC_MESSAGES/gettext_plugin.mo +0 -0
  97. data/samples/rails/locale/el/LC_MESSAGES/blog.mo +0 -0
  98. data/samples/rails/locale/el/LC_MESSAGES/gettext_plugin.mo +0 -0
  99. data/samples/rails/locale/en/LC_MESSAGES/blog.mo +0 -0
  100. data/samples/rails/locale/es/LC_MESSAGES/blog.mo +0 -0
  101. data/samples/rails/locale/es/LC_MESSAGES/gettext_plugin.mo +0 -0
  102. data/samples/rails/locale/fr/LC_MESSAGES/blog.mo +0 -0
  103. data/samples/rails/locale/fr/LC_MESSAGES/gettext_plugin.mo +0 -0
  104. data/samples/rails/locale/ja/LC_MESSAGES/blog.mo +0 -0
  105. data/samples/rails/locale/ja/LC_MESSAGES/gettext_plugin.mo +0 -0
  106. data/samples/rails/locale/ko/LC_MESSAGES/blog.mo +0 -0
  107. data/samples/rails/locale/ko/LC_MESSAGES/gettext_plugin.mo +0 -0
  108. data/samples/rails/locale/nl/LC_MESSAGES/blog.mo +0 -0
  109. data/samples/rails/locale/nl/LC_MESSAGES/gettext_plugin.mo +0 -0
  110. data/samples/rails/locale/pt_BR/LC_MESSAGES/blog.mo +0 -0
  111. data/samples/rails/locale/pt_BR/LC_MESSAGES/gettext_plugin.mo +0 -0
  112. data/samples/rails/po/blog.pot +1 -1
  113. data/samples/rails/po/cs/blog.po +1 -2
  114. data/samples/rails/po/cs/gettext_plugin.po +1 -1
  115. data/samples/rails/po/de/blog.po +1 -2
  116. data/samples/rails/po/de/gettext_plugin.po +1 -1
  117. data/samples/rails/po/el/blog.po +1 -1
  118. data/samples/rails/po/el/gettext_plugin.po +1 -1
  119. data/samples/rails/po/en/blog.po +1 -1
  120. data/samples/rails/po/es/blog.po +1 -2
  121. data/samples/rails/po/es/gettext_plugin.po +1 -1
  122. data/samples/rails/po/fr/blog.po +1 -1
  123. data/samples/rails/po/fr/gettext_plugin.po +1 -1
  124. data/samples/rails/po/gettext_plugin.pot +1 -1
  125. data/samples/rails/po/ja/blog.po +2 -1
  126. data/samples/rails/po/ja/gettext_plugin.po +1 -1
  127. data/samples/rails/po/ko/blog.po +1 -2
  128. data/samples/rails/po/ko/gettext_plugin.po +1 -1
  129. data/samples/rails/po/nl/blog.po +1 -3
  130. data/samples/rails/po/nl/gettext_plugin.po +1 -1
  131. data/samples/rails/po/pt_BR/blog.po +1 -1
  132. data/samples/rails/po/pt_BR/gettext_plugin.po +1 -1
  133. data/setup.rb +799 -574
  134. data/src/poparser.ry +6 -5
  135. data/test/gettext_runner.rb +3 -1
  136. data/test/gettext_test.rb +40 -24
  137. data/test/gettext_test_cgi.rb +60 -6
  138. data/test/gettext_test_locale.rb +136 -0
  139. data/test/gettext_test_parser.rb +12 -12
  140. data/test/locale/la/LC_MESSAGES/plural_error.mo +0 -0
  141. data/test/po/la/plural_error.po +21 -0
  142. data/test/test.bat +2 -0
  143. data/test/test.sh +2 -4
  144. data/test/test_rubyparser_n_.rb +64 -0
  145. metadata +24 -21
  146. data/ext/gettext/gettext/MANIFEST +0 -3
  147. data/ext/gettext/gettext/_locale-i386-mswin32.def +0 -2
  148. data/ext/gettext/gettext/_locale.exp +0 -0
  149. data/ext/gettext/gettext/_locale.lib +0 -0
  150. data/ext/gettext/gettext/_locale.obj +0 -0
  151. data/ext/gettext/gettext/_locale.so +0 -0
  152. data/ext/gettext/gettext/extconf.rb +0 -20
  153. data/ext/gettext/gettext/mkmf.log +0 -16
  154. data/lib/_locale.so +0 -0
  155. data/lib/gettext/locale_default.rb +0 -35
  156. data/po/it/messages.mo +0 -0
  157. data/samples/cgi/po/it/messages.mo +0 -0
data/lib/gettext/rails.rb CHANGED
@@ -1,28 +1,53 @@
1
1
  =begin
2
2
  gettext/rails.rb - GetText for "Ruby on Rails"
3
3
 
4
- Copyright (C) 2005 Masao Mutoh
4
+ Copyright (C) 2005,2006 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby.
8
8
 
9
- $Id: rails.rb,v 1.12 2006/01/14 13:48:22 mutoh Exp $
9
+ $Id: rails.rb,v 1.17 2006/02/23 14:53:59 mutoh Exp $
10
10
  =end
11
11
 
12
- require 'gettext'
13
12
  require 'gettext/cgi'
14
13
  require 'active_record'
15
14
  require 'active_support'
16
15
 
17
- module GetText
16
+ module GetText #:nodoc:
17
+ # = GetText for Ruby on Rails
18
+ # GetText::Rails supports Ruby on Rails.
19
+ # You add only 2 lines in your controller, all of the controller/view/models are
20
+ # targeted the textdomain.
21
+ #
22
+ # See <Ruby-GetText-Package HOWTO for Ruby on Rails (http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html>.
18
23
  module Rails
19
24
  include GetText
25
+ extend GetText
20
26
 
21
- Rails = ::Rails
27
+ Rails = ::Rails #:nodoc:
22
28
 
23
- alias :_bindtextdomain :bindtextdomain
29
+ alias :_bindtextdomain :bindtextdomain #:nodoc:
24
30
 
31
+ # Bind a textdomain(#{path}/#{locale}/LC_MESSAGES/#{domainname}.mo) to your program.
32
+ # Notes the textdomain scope becomes all of the controllers/views/models in your app.
33
+ # This is different from normal GetText.bindtextomain.
34
+ #
35
+ # Usually, you don't call this directly in your rails application.
36
+ # Call init_gettext in ActionController::Base instead.
37
+ #
38
+ # On the other hand, you need to call this in helpers/plugins.
39
+ #
40
+ # * domainname: the textdomain name.
41
+ # * locale: the locale value such as "ja-JP". When the value is nil,
42
+ # * charset: the charset. Generally UTF-8 is recommanded.
43
+ # * with_model: false if you want to ignore model support.
44
+ #
45
+ # locale is searched the order by this value > "lang" value of QUERY_STRING >
46
+ # "lang" value of Cookie > HTTP_ACCEPT_LANGUAGE value > Default locale(en).
47
+ # And the charset is set order by "the argument of bindtextdomain" > HTTP_ACCEPT_CHARSET > Default charset(UTF-8).
48
+ #
25
49
  def bindtextdomain(domainname, _cgi = nil, locale = nil, charset = nil, with_model = true)
50
+ Locale.clear # IMPORTANT! current locale should be nil once(default is used).
26
51
  set_cgi(_cgi) if _cgi
27
52
  @gettext_container_domainname = domainname
28
53
  path = File.join(RAILS_ROOT, "locale")
@@ -31,20 +56,20 @@ module GetText
31
56
  bindtextdomain_to(ActiveRecord::Base, domainname) if with_model
32
57
  end
33
58
 
34
- def bindtextdomain_to(klass, domainname)
59
+ def bindtextdomain_to(klass, domainname) #:nodoc:
35
60
  klass.class_eval {
36
61
  textdomain(domainname)
37
62
 
38
- def self.human_attribute_name(attribute_key_name)
63
+ def self.human_attribute_name(attribute_key_name) #:nodoc:
39
64
  s_("#{self}|#{attribute_key_name.humanize}")
40
65
  end
41
- def self.human_attribute_table_name_for_error(table_name)
66
+ def self.human_attribute_table_name_for_error(table_name) #:nodoc:
42
67
  _(table_name.gsub(/_/, " "))
43
68
  end
44
69
  }
45
70
  end
46
71
 
47
- def callersrc
72
+ def callersrc #:nodoc:
48
73
  @gettext_container_domainname = nil unless defined? @gettext_container_domainname
49
74
  @gettext_container_domainname
50
75
  end
@@ -52,7 +77,7 @@ module GetText
52
77
  end
53
78
 
54
79
 
55
- module ActionController
80
+ module ActionController #:nodoc:
56
81
  class Base
57
82
  helper GetText::Rails
58
83
  include GetText::Rails
@@ -62,13 +87,22 @@ module ActionController
62
87
  @@gettext_content_type = nil
63
88
 
64
89
  prepend_before_filter :init_gettext
65
-
66
- def init_gettext_main
90
+ after_filter :init_content_type
91
+
92
+ def init_gettext_main #:nodoc:
67
93
  bindtextdomain(@@gettext_domainname, request.cgi) #You need to pass CGI object first.
68
- @headers["Content-Type"] = "#{@@gettext_content_type}; charset=#{GetText.output_charset}"
69
94
  end
70
95
 
71
- def init_gettext
96
+ def init_content_type #:nodoc:
97
+ if @headers["Content-Type"] and /javascript/ =~ @headers["Content-Type"]
98
+ @headers["Content-Type"] = "text/javascript; charset=#{GetText.output_charset}"
99
+ elsif ! @headers["Content-Type"]
100
+ @headers["Content-Type"] = "#{@@gettext_content_type}; charset=#{GetText.output_charset}"
101
+ end
102
+ end
103
+
104
+
105
+ def init_gettext # :nodoc:
72
106
  init_gettext_main if @@gettext_domainname
73
107
  ActiveRecord::Errors.class_eval{
74
108
  # You need to call bindtextdomain here because ActiveRecord::Errors doesn't know
@@ -77,6 +111,21 @@ module ActionController
77
111
  }
78
112
  end
79
113
 
114
+ # Bind a 'textdomain' to all of the controllers/views/models. Call this instead of GetText.bindtextdomain.
115
+ # * textdomain: the textdomain
116
+ # * charset: the output charset. Default is "UTF-8"
117
+ # * content_type: the content type. Default is "text/html"
118
+ #
119
+ # If you want to separate the textdomain each controllers, you need to call this function in the each controllers.
120
+ #
121
+ # app/controller/blog_controller.rb:
122
+ # require 'gettext/rails'
123
+ #
124
+ # class BlogController < ApplicationController
125
+ # init_gettext "blog"
126
+ # :
127
+ # :
128
+ # end
80
129
  def self.init_gettext(domainname, charset = "UTF-8", content_type = "text/html")
81
130
  GetText.output_charset = charset
82
131
  @@gettext_domainname = domainname
@@ -84,7 +133,7 @@ module ActionController
84
133
  end
85
134
  end
86
135
 
87
- class TestRequest < AbstractRequest
136
+ class TestRequest < AbstractRequest #:nodoc:
88
137
  @cgi = nil
89
138
  def cgi
90
139
  @cgi = CGI.new unless @cgi
@@ -93,18 +142,38 @@ module ActionController
93
142
  end
94
143
  end
95
144
 
96
- module ActiveRecord
145
+ module ActiveRecord #:nodoc:
97
146
  class Base
98
- include GetText::Rails
99
- extend GetText::Rails
100
- end
147
+ include GetText::Rails # Important
148
+ extend GetText::Rails # Important
149
+
150
+ @@error_message_title = nil
151
+ @@error_message_explanation = nil
152
+
153
+ # Sets a your own title of error message dialog.
154
+ def self.set_error_message_title(single_msg, plural_msg)
155
+ @@error_message_title = [single_msg, plural_msg]
156
+ end
157
+
158
+ # Sets a your own explanation of the error message dialog.
159
+ def self.set_error_message_explanation(single_msg, plural_msg)
160
+ @@error_message_explanation = [single_msg, plural_msg]
161
+ end
101
162
 
102
- class Errors
163
+ def error_message_title #:nodoc:
164
+ @@error_message_title
165
+ end
166
+ def error_message_explanation #:nodoc:
167
+ @@error_message_explanation
168
+ end
169
+ end
170
+
171
+ class Errors #:nodoc:
103
172
  include GetText
104
173
  extend GetText
105
174
 
106
- RE_FIELD_NAME = /%\{fn\}/
107
-
175
+ RE_FIELD_NAME = /%\{fn\}/ #:nodoc:
176
+
108
177
  # You need to define this here, because this values will be updated by application.
109
178
  default_error_messages.update(
110
179
  :inclusion => N_("%{fn} is not included in the list"),
@@ -120,22 +189,20 @@ module ActiveRecord
120
189
  :taken => N_("%{fn} has already been taken"),
121
190
  :not_a_number => N_("%{fn} is not a number")
122
191
  )
123
-
124
192
  @@default_error_messages_d = {
125
193
  :too_long => default_error_messages[:too_long],
126
194
  :too_short => default_error_messages[:too_short],
127
195
  :wrong_length => default_error_messages[:wrong_length]
128
196
  }
129
197
 
130
- def self.convert_validates_messages_of_validates_length_of
198
+ def self.convert_validates_messages_of_validates_length_of #:nodoc:
131
199
  default_error_messages[:too_long] = _(@@default_error_messages_d[:too_long])
132
200
  default_error_messages[:too_short] = _(@@default_error_messages_d[:too_short])
133
201
  default_error_messages[:wrong_length] = _(@@default_error_messages_d[:wrong_length])
134
202
  end
135
203
 
136
- def full_messages
204
+ def full_messages #:nodoc:
137
205
  full_messages = []
138
-
139
206
  @errors.each_key do |attr|
140
207
  @errors[attr].each do |msg|
141
208
  next if msg.nil?
@@ -152,8 +219,8 @@ module ActiveRecord
152
219
  end
153
220
  end
154
221
 
155
- module Validations
156
- module ClassMethods
222
+ module Validations #:nodoc:
223
+ module ClassMethods #:nodoc:
157
224
  alias :_validates_length_of :validates_length_of
158
225
  def validates_length_of(*attrs)
159
226
  ActiveRecord::Errors.convert_validates_messages_of_validates_length_of
@@ -164,33 +231,44 @@ module ActiveRecord
164
231
  end
165
232
 
166
233
 
167
- module ActionView
168
- module Helpers
169
- module ActiveRecordHelper
234
+ module ActionView #:nodoc:
235
+ module Helpers #:nodoc:
236
+ module ActiveRecordHelper #:nodoc: all
170
237
  module L10n
171
238
  # Separate namespace for textdomain
172
239
  include GetText
173
240
  extend GetText
241
+
242
+ @error_message_title = Nn_("%{num} error prohibited this %{record} from being saved",
243
+ "%{num} errors prohibited this %{record} from being saved")
244
+ @error_message_explanation = Nn_("There was a problem with the following field:",
245
+ "There were problems with the following fields:")
246
+
174
247
  module_function
248
+ def render_error_message(object, klass, record, count, options)
249
+ message_title = object.error_message_title || @error_message_title
250
+ message_explanation = object.error_message_explanation || @error_message_explanation
251
+
252
+ klass.content_tag("div",
253
+ klass.content_tag(
254
+ options[:header_tag] || "h2",
255
+ n_(message_title, count) % {:num => count, :record => record}
256
+ ) +
257
+ klass.content_tag("p", n_(message_explanation, count) % {:num => count}) +
258
+ klass.content_tag("ul", object.errors.full_messages.collect { |msg| klass.content_tag("li", msg) }),
259
+ "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
260
+ )
261
+ end
262
+
175
263
  def error_messages_for(object, object_name, klass, options = {})
176
264
  textdomain("rails")
177
265
 
178
266
  options = options.symbolize_keys
179
-
267
+
180
268
  unless object.errors.empty?
181
269
  count = object.errors.count
182
270
  record = ActiveRecord::Base.human_attribute_table_name_for_error(object_name)
183
- klass.content_tag("div",
184
- klass.content_tag(
185
- options[:header_tag] || "h2",
186
- n_("%{num} error prohibited this %{record} from being saved",
187
- "%{num} errors prohibited this %{record} from being saved", count) %
188
- {:num => count, :record => record}) +
189
- klass.content_tag("p", n_("There were problems with the following field:",
190
- "There were problems with the following fields:", count)) +
191
- klass.content_tag("ul", object.errors.full_messages.collect { |msg| klass.content_tag("li", msg) }),
192
- "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
193
- )
271
+ render_error_message(object, klass, record, count, options)
194
272
  end
195
273
  end
196
274
  end
@@ -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