Class: Translatomatic::ResourceFile::XML

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

Overview

XML resource file

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

#create_variable, #format, #get, #locale_path, #sentences, #supports_variable_interpolation?, #to_s, #valid?, #variable_regex

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



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

def initialize(path, locale = nil)
  super(path, locale)
  @valid = true
  @nodemap = {}
  @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



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

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



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

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



19
20
21
22
# File 'lib/translatomatic/resource_file/xml.rb', line 19

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