Class: Translatomatic::ResourceFile::Properties

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

Overview

Properties resource file

Instance Attribute Summary

Attributes inherited from Base

#locale, #path, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

enabled?, #format, #get, #initialize, #locale_path, #sentences, #set, #to_s, #type

Constructor Details

This class inherits a constructor from Translatomatic::ResourceFile::Base

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



9
10
11
# File 'lib/translatomatic/resource_file/properties.rb', line 9

def self.extensions
  %w{properties}
end

.is_key_value?boolean

Returns True if the file format consists of keys and values.

Returns:

  • (boolean)

    True if the file format consists of keys and values



14
15
16
# File 'lib/translatomatic/resource_file/properties.rb', line 14

def self.is_key_value?
  true
end

.supports_variable_interpolation?boolean

Returns true if this resource file supports variable interpolation.

Returns:

  • (boolean)

    true if this resource file supports variable interpolation



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

def self.supports_variable_interpolation?
  true
end

Instance Method Details

#create_variable(name) ⇒ String

Create an interpolated variable string.

Returns:

  • (String)

    A string representing the interpolated variable, or nil if this resource file doesn’t support variable interpolation.



38
39
40
# File 'lib/translatomatic/resource_file/properties.rb', line 38

def create_variable(name)
  return "{#{name}}"
end

#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



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/translatomatic/resource_file/properties.rb', line 24

def save(target = path, options = {})
  out = ""
  out += add_created_by unless options[:no_created_by]
  properties.each do |key, value|
    # TODO: maintain original line ending format?
    value = value.gsub("\n", "\\n") if value  # convert newlines to \n
    out += "#{key} = #{value}\n"
  end
  # escape unicode characters
  out = Translatomatic::EscapedUnicode.escape(out)
  target.write(out)
end

#variable_regexRegexp

Returns A regexp used to match interpolated variables.

Returns:

  • (Regexp)

    A regexp used to match interpolated variables



43
44
45
# File 'lib/translatomatic/resource_file/properties.rb', line 43

def variable_regex
  /\{.*?\}/
end