Class: GetText::Tools::Task

Inherits:
Object
  • Object
show all
Includes:
GetText, Rake::DSL
Defined in:
lib/gettext/tools/task.rb

Defined Under Namespace

Classes: Error, Path, ValidationError

Constant Summary

Constants included from GetText

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetText

#N_, #Nn_, #bindtextdomain, #bindtextdomain_to, #cgi, #cgi=, #gettext, included, #locale, #ngettext, #npgettext, #nsgettext, #output_charset, #pgettext, #set_cgi, #set_current_locale, #set_locale, #set_output_charset, #sgettext, #textdomain, #textdomain_to

Constructor Details

#initialize(spec = nil) ⇒ Task

Returns a new instance of Task.

Parameters:

  • spec (Gem::Specification, nil) (defaults to: nil)

    Package information associated with the task. Some information are extracted from the spec.

See Also:



174
175
176
177
178
179
180
181
182
# File 'lib/gettext/tools/task.rb', line 174

def initialize(spec=nil)
  initialize_variables
  self.spec = spec
  if spec
    yield(self) if block_given?
    warn("Use #{self.class.name}.define instead of #{self.class.name}.new(spec).")
    define
  end
end

Instance Attribute Details

#domainString

It is a required parameter.

Returns:

  • (String)

    Text domain



106
107
108
# File 'lib/gettext/tools/task.rb', line 106

def domain
  @domain
end

#enable_description=(value) ⇒ Bool (writeonly)

Returns:

  • (Bool)

See Also:



144
145
146
# File 'lib/gettext/tools/task.rb', line 144

def enable_description=(value)
  @enable_description = value
end

#enable_po=(value) ⇒ Bool (writeonly)

Returns:

  • (Bool)

See Also:



148
149
150
# File 'lib/gettext/tools/task.rb', line 148

def enable_po=(value)
  @enable_po = value
end

#filesArray<String>

It is a required parameter.

Returns:

  • (Array<String>)

    Files that have messages.



102
103
104
# File 'lib/gettext/tools/task.rb', line 102

def files
  @files
end

#localesArray<String>

It is a required parameter.

Returns:



93
94
95
# File 'lib/gettext/tools/task.rb', line 93

def locales
  @locales
end

#mo_base_directoryString

Returns Base directory that has generated MOs. MOs are generated into #{mo_base_directory}/#{locale}/LC_MESSAGES/#{domain}.mo.

Returns:

  • (String)

    Base directory that has generated MOs. MOs are generated into #{mo_base_directory}/#{locale}/LC_MESSAGES/#{domain}.mo.



98
99
100
# File 'lib/gettext/tools/task.rb', line 98

def mo_base_directory
  @mo_base_directory
end

#msgcat_optionsArray<String>

Returns Command line options for filtering PO.

Returns:

  • (Array<String>)

    Command line options for filtering PO.

See Also:

Since:

  • 3.1.3



140
141
142
# File 'lib/gettext/tools/task.rb', line 140

def msgcat_options
  @msgcat_options
end

#msginit_optionsArray<String>

Returns Command line options for creating PO from POT.

Returns:

  • (Array<String>)

    Command line options for creating PO from POT.

See Also:



128
129
130
# File 'lib/gettext/tools/task.rb', line 128

def msginit_options
  @msginit_options
end

#msgmerge_optionsArray<String>

Returns Command line options for merging PO with the latest POT.

Returns:

  • (Array<String>)

    Command line options for merging PO with the latest POT.

See Also:



134
135
136
# File 'lib/gettext/tools/task.rb', line 134

def msgmerge_options
  @msgmerge_options
end

#namespace_prefixString

It is useful when you have multiple domains. You can define tasks for each domains by using different namespace prefix.

It is nil by default. It means that tasks are defined at top level.

TODO: example

Returns:

  • (String)

    Namespace prefix for tasks defined by this class.



117
118
119
# File 'lib/gettext/tools/task.rb', line 117

def namespace_prefix
  @namespace_prefix
end

#package_nameString?

Returns Package name for messages.

Returns:

  • (String, nil)

    Package name for messages.



84
85
86
# File 'lib/gettext/tools/task.rb', line 84

def package_name
  @package_name
end

#package_versionString?

Returns Package version for messages.

Returns:

  • (String, nil)

    Package version for messages.



87
88
89
# File 'lib/gettext/tools/task.rb', line 87

def package_version
  @package_version
end

#po_base_directoryObject

Returns the value of attribute po_base_directory.



94
95
96
# File 'lib/gettext/tools/task.rb', line 94

def po_base_directory
  @po_base_directory
end

#pot_creatorProc

It is used to custom how to create POT file. The object must have call method. The method must accept one argument. The argument is a Pathname object that represents POT file path.

Examples:


GetText::Tools::Task.define do |task|
  task.pot_creator = lambda do |pot_file_path|
    pot_file_path.open("w") do |pot_file|
      pot_file << <<-POT
msgid "Hello"
msgstr ""
      POT
    end
  end
end

Returns:

  • (Proc)


169
170
171
# File 'lib/gettext/tools/task.rb', line 169

def pot_creator
  @pot_creator
end

#specGem::Specification?

Returns Package information associated with the task.

Returns:

  • (Gem::Specification, nil)

    Package information associated with the task.



81
82
83
# File 'lib/gettext/tools/task.rb', line 81

def spec
  @spec
end

#xgettext_optionsArray<String>

Returns Command line options for extracting messages from sources.

Returns:

  • (Array<String>)

    Command line options for extracting messages from sources.

See Also:



123
124
125
# File 'lib/gettext/tools/task.rb', line 123

def xgettext_options
  @xgettext_options
end

Class Method Details

.define {|task| ... } ⇒ void

This method returns an undefined value.

Define gettext related Rake tasks. Normally, use this method to define tasks because this method is a convenient API.

See accessor APIs how to configure this task.

See #define for what task is defined.

Examples:

Recommended usage

require "gettext/tools/task"
# Recommended usage
GetText::Tools::Task.define do |task|
  task.spec = spec
  # ...
end
# Low level API
task = GetText::Tools::Task.new
task.spec = spec
# ...
task.define

Yields:

  • (task)

    Gives the newely created task to the block.

Yield Parameters:

See Also:



72
73
74
75
76
# File 'lib/gettext/tools/task.rb', line 72

def define
  task = new
  yield(task)
  task.define
end

Instance Method Details

#defineObject

Define tasks from configured parameters.

TODO: List defined Rake tasks.



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/gettext/tools/task.rb', line 207

def define
  ensure_variables
  validate

  define_file_tasks
  if namespace_prefix
    namespace_recursive namespace_prefix do
      define_named_tasks
    end
  else
    define_named_tasks
  end
end

#enable_description?Bool

If it is true, each task has description. Otherwise, all tasks doesn't have description.

Returns:

  • (Bool)

Since:

  • 3.0.1



226
227
228
# File 'lib/gettext/tools/task.rb', line 226

def enable_description?
  @enable_description
end

#enable_po?Bool

If it is true, PO related tasks are defined. Otherwise, they are not defined.

This parameter is useful to manage PO written by hand.

Returns:

  • (Bool)

Since:

  • 3.0.1



237
238
239
# File 'lib/gettext/tools/task.rb', line 237

def enable_po?
  @enable_po
end