Class: Translatomatic::ResourceFile::XCodeStrings

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

Overview

XCode strings resource file

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, #set, #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



31
32
33
34
35
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 31

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



26
27
28
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 26

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



38
39
40
41
42
43
44
45
46
47
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 38

def save(target = path, options = {})
  out = ""
  out += comment(created_by) unless options[:no_created_by]
  properties.each do |key, value|
    key = escape(key)
    value = escape(value)
    out += %Q{"#{key}" = "#{value}";\n}
  end
  target.write(out)
end