Class: GetText::Tools::XGetText
- Inherits:
-
Object
- Object
- GetText::Tools::XGetText
- Includes:
- GetText
- Defined in:
- lib/gettext/tools/xgettext.rb
Constant Summary collapse
- @@default_parsers =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
[]
Constants included from GetText
BOM_UTF8, MOFile, MoFile, PoParser, VERSION
Class Method Summary collapse
-
.add_parser(parser) ⇒ void
Adds a parser to the default parser list.
- .run(*arguments) ⇒ Object
Instance Method Summary collapse
-
#add_parser(parser) ⇒ void
The parser object requires to have target?(path) and parse(path) method.
-
#check_command_line_options(*options) ⇒ Object
:nodoc:.
-
#generate_pot(paths) ⇒ Object
:nodoc:.
-
#generate_pot_header ⇒ Object
:nodoc:.
-
#initialize ⇒ XGetText
constructor
:nodoc:.
-
#parse(paths) ⇒ Object
:nodoc:.
-
#parse_arguments(*options) ⇒ Object
:nodoc:.
-
#run(*options) ⇒ Object
:nodoc:.
Methods included from GetText
#N_, #Nn_, #bindtextdomain, #bindtextdomain_to, #cgi, #cgi=, #create_mofiles, #create_mofiles_org, #gettext, included, #locale, #msgmerge, #ngettext, #npgettext, #nsgettext, #output_charset, #pgettext, #remove_bom, #set_cgi, #set_current_locale, #set_locale, #set_output_charset, #sgettext, #textdomain, #textdomain_to, #update_pofiles, #update_pofiles_org
Constructor Details
#initialize ⇒ XGetText
:nodoc:
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gettext/tools/xgettext.rb', line 69 def initialize #:nodoc: @parsers = @@default_parsers @input_files = nil @output = nil @package_name = nil @package_version = nil @msgid_bugs_address = nil @copyright_holder = nil @output_encoding = nil end |
Class Method Details
.add_parser(parser) ⇒ void
This method returns an undefined value.
Adds a parser to the default parser list.
42 43 44 |
# File 'lib/gettext/tools/xgettext.rb', line 42 def add_parser(parser) @@default_parsers.unshift(parser) end |
.run(*arguments) ⇒ Object
32 33 34 |
# File 'lib/gettext/tools/xgettext.rb', line 32 def run(*arguments) new.run(*arguments) end |
Instance Method Details
#add_parser(parser) ⇒ void
This method returns an undefined value.
The parser object requires to have target?(path) and parse(path) method.
129 130 131 |
# File 'lib/gettext/tools/xgettext.rb', line 129 def add_parser(parser) @parsers.unshift(parser) end |
#check_command_line_options(*options) ⇒ Object
:nodoc:
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/gettext/tools/xgettext.rb', line 182 def (*) # :nodoc: input_files, output = parse_arguments(*) if input_files.empty? raise ArgumentError, _("no input files") end output ||= STDOUT @input_files = input_files @output = output @package_name ||= "PACKAGE" @package_version ||= "VERSION" @msgid_bugs_address ||= "" @copyright_holder ||= "THE PACKAGE'S COPYRIGHT HOLDER" end |
#generate_pot(paths) ⇒ Object
:nodoc:
159 160 161 162 163 164 165 166 |
# File 'lib/gettext/tools/xgettext.rb', line 159 def generate_pot(paths) # :nodoc: po = parse(paths) entries = [] po.each do |target| entries << encode(target.to_s) end entries.join("\n") end |
#generate_pot_header ⇒ Object
:nodoc:
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/gettext/tools/xgettext.rb', line 133 def generate_pot_header # :nodoc: time = now.strftime("%Y-%m-%d %H:%M%z") <<EOH # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR #{@copyright_holder} # This file is distributed under the same license as the #{@package_name} package. # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: #{@package_name} #{@package_version}\\n" "Report-Msgid-Bugs-To: #{@msgid_bugs_address}\\n" "POT-Creation-Date: #{time}\\n" "PO-Revision-Date: #{time}\\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" "Language-Team: LANGUAGE <[email protected]>\\n" "Language: \\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=#{@output_encoding}\\n" "Content-Transfer-Encoding: 8bit\\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n" EOH end |
#parse(paths) ⇒ Object
:nodoc:
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gettext/tools/xgettext.rb', line 168 def parse(paths) # :nodoc: po = [] paths = [paths] if paths.kind_of?(String) paths.each do |path| begin parse_path(path, po) rescue puts(_("Error parsing %{path}") % {:path => path}) raise end end po end |
#parse_arguments(*options) ⇒ Object
:nodoc:
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/gettext/tools/xgettext.rb', line 200 def parse_arguments(*) #:nodoc: output = nil parser = OptionParser.new = _("Usage: %s input.rb [-r parser.rb] [-o output.pot]") % $0 parser. = parser.separator("") description = _("Extract translatable strings from given input files.") parser.separator(description) parser.separator("") parser.separator(_("Specific options:")) parser.on("-o", "--output=FILE", _("write output to specified file")) do |out| output = out end parser.on("--package-name=PACKAGE", _("set package name in output")) do |out| @package_name = out end parser.on("--package-version=VERSION", _("set package version in output")) do |out| @package_version = out end parser.on("--msgid-bugs-address=EMAIL", _("set report address for msgid bugs")) do |out| @msgid_bugs_address = out end parser.on("--copyright-holder=STRING", _("set copyright holder in output")) do |out| @copyright_holder = out end parser.on("--output-encoding=ENCODING", _("set encoding for output")) do |encoding| @output_encoding = encoding end parser.on("-r", "--require=library", _("require the library before executing xgettext")) do |out| require out end parser.on("-d", "--debug", _("run in debugging mode")) do $DEBUG = true end parser.on("-h", "--help", _("display this help and exit")) do puts(parser.help) exit(true) end parser.on_tail("--version", _("display version information and exit")) do puts(GetText::VERSION) exit(true) end parser.parse!() [, output] end |
#run(*options) ⇒ Object
:nodoc:
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gettext/tools/xgettext.rb', line 266 def run(*) # :nodoc: (*) @output_encoding ||= "UTF-8" pot = generate_pot_header pot << "\n" pot << generate_pot(@input_files) if @output.is_a?(String) File.open(File.(@output), "w+") do |file| file.puts(pot) end else @output.puts(pot) end self end |