Class: Translatomatic::ResourceFile::Properties
- Defined in:
- lib/translatomatic/resource_file/properties.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.extensions ⇒ Array<String>
File extensions supported by this resource file.
Instance Method Summary collapse
-
#initialize(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
constructor
Create a new resource file.
-
#save(target = path, options = {}) ⇒ void
Save the resource file.
Methods inherited from Base
#format, #get, #locale_path, #sentences, #set, #to_s, #valid?
Methods included from Util
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.
12 13 14 15 16 |
# File 'lib/translatomatic/resource_file/properties.rb', line 12 def initialize(path, locale = nil) super(path, locale) @valid = true @properties = @path.exist? ? read(@path) : {} end |
Class Method Details
.extensions ⇒ Array<String>
7 8 9 |
# File 'lib/translatomatic/resource_file/properties.rb', line 7 def self.extensions %w{properties} end |
Instance Method Details
#save(target = path, options = {}) ⇒ void
This method returns an undefined value.
Save the resource file.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/translatomatic/resource_file/properties.rb', line 19 def save(target = path, = {}) out = "" out += add_created_by unless [:no_created_by] properties.each do |key, value| # TODO: maintain original line ending format? value = value.gsub("\n", "\\n") # convert newlines to \n out += "#{key} = #{value}\n" end # escape unicode characters out = Translatomatic::EscapedUnicode.escape(out) target.write(out) end |