Class: Translatomatic::ResourceFile::Text

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

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, #set, #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/text.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/text.rb', line 5

def self.extensions
  %w{txt text}
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



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

def save(target = path, options = {})
  values = @properties.values.collect { |i| i.strip + "\n" }
  target.write(values.join)
end