Class: Translatomatic::ResourceFile::Properties
- Defined in:
- lib/translatomatic/resource_file/properties.rb
Overview
Properties resource file
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
-
#create_variable(name) ⇒ String
Create an interpolated variable string.
-
#initialize(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
constructor
Create a new resource file.
-
#save(target = path, options = {}) ⇒ void
Save the resource file.
-
#supports_variable_interpolation? ⇒ boolean
True if this resource file supports variable interpolation.
-
#variable_regex ⇒ Regexp
A regexp used to match interpolated variables.
Methods inherited from Base
#format, #get, #locale_path, #sentences, #set, #to_s, #valid?
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.
14 15 16 17 18 |
# File 'lib/translatomatic/resource_file/properties.rb', line 14 def initialize(path, locale = nil) super(path, locale) @valid = true @properties = @path.exist? ? read(@path) : {} end |
Class Method Details
.extensions ⇒ Array<String>
Returns 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 |
Instance Method Details
#create_variable(name) ⇒ String
Create an interpolated variable string.
40 41 42 |
# File 'lib/translatomatic/resource_file/properties.rb', line 40 def create_variable(name) return "{#{name}}" end |
#save(target = path, options = {}) ⇒ void
This method returns an undefined value.
Save the resource file.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/translatomatic/resource_file/properties.rb', line 21 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") if value # convert newlines to \n out += "#{key} = #{value}\n" end # escape unicode characters out = Translatomatic::EscapedUnicode.escape(out) target.write(out) end |
#supports_variable_interpolation? ⇒ boolean
Returns true if this resource file supports variable interpolation.
35 36 37 |
# File 'lib/translatomatic/resource_file/properties.rb', line 35 def supports_variable_interpolation? true end |
#variable_regex ⇒ Regexp
Returns A regexp used to match interpolated variables.
45 46 47 |
# File 'lib/translatomatic/resource_file/properties.rb', line 45 def variable_regex /\{.*?\}/ end |