fair-gettext 2.0.0 → 2.0.1

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/gettext.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fair-gettext}
5
- s.version = "2.0.0"
5
+ s.version = "2.0.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Masao Mutoh"]
data/lib/gettext/tools.rb CHANGED
@@ -1,29 +1,29 @@
1
1
  =begin
2
2
  tools.rb - Utility functions
3
-
3
+
4
4
  Copyright (C) 2005-2008 Masao Mutoh
5
-
5
+
6
6
  You may redistribute it and/or modify it under the same
7
7
  license terms as Ruby or LGPL.
8
8
  =end
9
-
9
+
10
10
  require 'rbconfig'
11
11
  if /mingw|mswin|mswin32/ =~ RUBY_PLATFORM
12
12
  ENV['PATH'] = %w(bin lib).collect{|dir|
13
13
  "#{Config::CONFIG["prefix"]}\\lib\\GTK\\#{dir};"
14
14
  }.join('') + ENV['PATH']
15
15
  end
16
-
16
+
17
17
  require 'gettext/tools/rgettext'
18
18
  require 'gettext/tools/rmsgfmt'
19
19
  require 'gettext/runtime/mofile'
20
20
  require 'fileutils'
21
-
21
+
22
22
  module GetText
23
23
  bindtextdomain "rgettext"
24
-
24
+
25
25
  BOM_UTF8 = [0xef, 0xbb, 0xbf].pack("c3")
26
-
26
+
27
27
  # Currently, GNU msgmerge doesn't accept BOM.
28
28
  # This mesthod remove the UTF-8 BOM from the po-file.
29
29
  def remove_bom(path) #:nodoc:
@@ -33,7 +33,7 @@ module GetText
33
33
  File.open(path, "w") {|f| f.write(data)}
34
34
  end
35
35
  end
36
-
36
+
37
37
  # Merges two Uniforum style .po files together.
38
38
  #
39
39
  # *Note* This function requires "msgmerge" tool included in GNU GetText. So you need to install GNU GetText.
@@ -58,7 +58,7 @@ module GetText
58
58
  verbose = options.delete(:verbose)
59
59
  puts "msgmerge called" if verbose
60
60
  $stderr.print defpo + " "
61
-
61
+
62
62
  content = merge_po_files(defpo,refpo,options.delete(:msgmerge),verbose)
63
63
 
64
64
  if content.empty?
@@ -76,7 +76,7 @@ module GetText
76
76
 
77
77
  self
78
78
  end
79
-
79
+
80
80
  # Creates mo-files using #{po_root}/#{lang}/*.po an put them to
81
81
  # #{targetdir}/#{targetdir_rule}/.
82
82
  #
@@ -88,7 +88,7 @@ module GetText
88
88
  # * mo_path_rule: the target directory for each mo-files.
89
89
  def create_mofiles(options = {})
90
90
  options = {:po_root => "./po"}.merge(options)
91
-
91
+
92
92
  Dir.glob(File.join(options[:po_root], "*/*.po")) do |po_file|
93
93
  mo_file = mo_file_from_po_file(po_file,options)
94
94
  $stderr.print %Q[#{po_file} -> #{mo_file} ... ] if options[:verbose]
@@ -97,8 +97,8 @@ module GetText
97
97
  $stderr.puts "Done." if options[:verbose]
98
98
  end
99
99
  end
100
-
101
-
100
+
101
+
102
102
  # At first, this creates the #{po_root}/#{domainname}.pot file using GetText.rgettext.
103
103
  # In the second step, this updates(merges) the #{po_root}/#{domainname}.pot and all of the
104
104
  # #{po_root}/#{lang}/#{domainname}.po files under "po_root" using "msgmerge".
@@ -120,67 +120,60 @@ module GetText
120
120
  # Example: GetText.update_pofiles("myapp", Dir.glob("lib/*.rb"), "myapp 1.0.0", :verbose => true)
121
121
  def update_pofiles(textdomain, files, app_version, options = {})
122
122
  puts options.inspect if options[:verbose]
123
-
124
- #write found messages to tmp.pot and private_tmp.pot
123
+
124
+ #write found messages to tmp.pot
125
125
  temp_pot = "tmp.pot"
126
- private_temp_pot = "private_tmp.pot"
127
- rgettext(files, temp_pot, private_temp_pot)
128
-
129
- #merge tmp.pot and private_tmp.pot with existing pot
126
+ rgettext(files, temp_pot)
127
+
128
+ #merge tmp.pot and existing pot
130
129
  po_root = options.delete(:po_root) || "po"
131
130
  FileUtils.mkdir_p(po_root)
132
131
  msgmerge("#{po_root}/#{textdomain}.pot", temp_pot, app_version, options.dup)
133
- msgmerge("#{po_root}/private_#{textdomain}.pot", private_temp_pot, app_version, options.dup)
134
-
132
+
135
133
  #update local po-files
136
134
  only_one_language = options.delete(:lang)
137
135
  if only_one_language
138
136
  msgmerge("#{po_root}/#{only_one_language}/#{textdomain}.po", temp_pot, app_version, options.dup)
139
- msgmerge("#{po_root}/#{only_one_language}/private_#{textdomain}.po", private_temp_pot, app_version, options.dup)
140
137
  else
141
138
  Dir.glob("#{po_root}/*/#{textdomain}.po") do |po_file|
142
139
  msgmerge(po_file, temp_pot, app_version, options.dup)
143
140
  end
144
- Dir.glob("#{po_root}/*/private_#{textdomain}.po") do |po_file|
145
- msgmerge(po_file, private_temp_pot, app_version, options.dup)
146
- end
147
141
  end
148
-
142
+
149
143
  File.delete(temp_pot)
150
- File.delete(private_temp_pot)
151
144
  end
152
-
145
+
153
146
  private
154
-
147
+
155
148
  # Merge 2 po files, using msgmerge
156
149
  def merge_po_files(po_a,po_b,msgmerge_options=[],verbose=false)
157
150
  return File.read(po_b) unless FileTest.exist? po_a
158
-
151
+
159
152
  cmd = ENV["MSGMERGE_PATH"] || "msgmerge"
160
153
  ensure_command_exists(cmd)
161
-
154
+
162
155
  remove_bom(po_a)
163
-
156
+
164
157
  cmd_params = array_to_cli_options(msgmerge_options)
165
158
  to_run = "#{cmd} #{cmd_params} #{po_a} #{po_b}"
166
159
  puts "\nrunning #{to_run}" if verbose
167
160
  `#{to_run}`
168
161
  end
169
-
162
+
170
163
  # convert an array of String/Symbol to cli options
171
164
  def array_to_cli_options(array)
172
165
  [*array].map do |o|
173
166
  o.kind_of?(Symbol) ? "--#{o}".gsub('_','-') : o.to_s
174
167
  end.join(' ')
175
168
  end
176
-
169
+
177
170
  def ensure_command_exists(cmd)
178
171
  `#{cmd} --help`
179
172
  unless $? && $?.success?
180
173
  raise _("`%{cmd}' can not be found. \nInstall GNU Gettext then set PATH or MSGMERGE_PATH correctly.") % {:cmd => cmd}
181
174
  end
182
175
  end
183
-
176
+
184
177
  # where lies the mo file for a given po_file
185
178
  # generare directory unless it exists
186
179
  def mo_file_from_po_file(po_file,options)
@@ -190,13 +183,13 @@ module GetText
190
183
  }.merge(options)
191
184
 
192
185
  lang, textdomain = %r[/([^/]+?)/(.*)\.po].match(po_file[options[:po_root].size..-1]).to_a[1,2]
193
-
186
+
194
187
  mo_dir_rule = File.join(options[:mo_root], options[:mo_path_rule])
195
188
  mo_dir = mo_dir_rule % {:lang => lang}
196
189
  File.join(mo_dir, "#{textdomain}.mo")
197
190
  end
198
191
  end
199
-
192
+
200
193
  if __FILE__ == $0
201
194
  GetText.update_pofiles("foo", ARGV, "foo 1.1.0")
202
- end
195
+ end
@@ -91,30 +91,14 @@ msgstr ""
91
91
  TITLE
92
92
  end
93
93
 
94
- #PARSE HERE
95
94
  def generate_pot(paths) # :nodoc:
96
95
  pomessages = parse(paths)
97
96
  str = ""
98
-
99
97
  pomessages.each do |target|
100
- unless target.to_po_str.include? "[private]"
101
- str << target.to_po_str
102
- end
98
+ str << target.to_po_str
103
99
  end
104
100
  str
105
101
  end
106
-
107
- def generate_private_pot(paths)
108
- pomessages = parse(paths)
109
- private_str = ""
110
-
111
- pomessages.each do |target|
112
- if target.to_po_str.include? "[private]"
113
- private_str << target.to_po_str
114
- end
115
- end
116
- private_str
117
- end
118
102
 
119
103
  def parse(paths) # :nodoc:
120
104
  pomessages = []
@@ -197,7 +181,7 @@ TITLE
197
181
  [ARGV, output]
198
182
  end
199
183
 
200
- def run(paths = nil, out = STDOUT, private_out)
184
+ def run(paths = nil, out = STDOUT) # :nodoc:
201
185
  if paths.is_a? String
202
186
  paths = [paths]
203
187
  elsif ! paths
@@ -208,20 +192,14 @@ TITLE
208
192
  raise ArgumentError, _("no input files")
209
193
  end
210
194
 
211
- if ((out.is_a? String) and (private_out.is_a? String))
195
+ if out.is_a? String
212
196
  File.open(File.expand_path(out), "w+") do |file|
213
197
  file.puts generate_pot_header
214
198
  file.puts generate_pot(paths)
215
199
  end
216
- File.open(File.expand_path(private_out), "w+") do |file|
217
- file.puts generate_pot_header
218
- file.puts generate_private_pot(paths)
219
- end
220
200
  else
221
201
  out.puts generate_pot_header
222
202
  out.puts generate_pot(paths)
223
- private_out.puts generate_pot_header
224
- private_out.puts generate_private_pot(paths)
225
203
  end
226
204
  self
227
205
  end
@@ -236,8 +214,8 @@ TITLE
236
214
  # * paths: An Array of po-file paths or nil.
237
215
  # * out: output IO or output path.
238
216
  # * Returns: self
239
- def rgettext(paths = nil, out = STDOUT, private_out)
240
- RGetText.run(paths, out, private_out)
217
+ def rgettext(paths = nil, out = STDOUT)
218
+ RGetText.run(paths, out)
241
219
  self
242
220
  end
243
221
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ version: 2.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Masao Mutoh