Class: Translatomatic::ResourceFile::XML

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/resource_file/xml.rb

Direct Known Subclasses

HTML, Plist, RESW

Instance Attribute Summary

Attributes inherited from Base

#locale, #path, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#format, #get, #locale_path, #sentences, #to_s, #valid?

Methods included from Util

#locale, #log, #string

Constructor Details

#initialize(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base

Create a new resource file. If locale is unspecified, attempts to determine the locale of the file automatically, and if that fails, uses the default locale.

Parameters:

  • path (String)

    Path to the file

  • locale (String) (defaults to: nil)

    Locale of the file contents



10
11
12
13
14
# File 'lib/translatomatic/resource_file/xml.rb', line 10

def initialize(path, locale = nil)
  super(path, locale)
  @valid = true
  @properties = @path.exist? ? read(@path) : {}
end

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



5
6
7
# File 'lib/translatomatic/resource_file/xml.rb', line 5

def self.extensions
  %w{xml}
end

Instance Method Details

#save(target = path, options = {}) ⇒ void

This method returns an undefined value.

Save the resource file.

Parameters:

  • target (Pathname) (defaults to: path)

    The destination path

  • options (Hash<Symbol, Object>) (defaults to: {})

    Output format options



23
24
25
26
27
28
# File 'lib/translatomatic/resource_file/xml.rb', line 23

def save(target = path, options = {})
  if @doc
    add_created_by unless options[:no_created_by]
    target.write(@doc.to_xml)
  end
end

#set(key, value) ⇒ String

Set a property

Parameters:

  • key (String)

    The name of the property

  • value (String)

    The new value of the property

Returns:

  • (String)

    The new value of the property



17
18
19
20
# File 'lib/translatomatic/resource_file/xml.rb', line 17

def set(key, value)
  super(key, value)
  @nodemap[key].content = value if @nodemap.include?(key)
end