class Translatomatic::ResourceFile::YAML
YAML
resource file @see www.yaml.org/
Public Class Methods
extensions()
click to toggle source
(see Base.extensions
)
# File lib/translatomatic/resource_file/yaml.rb, line 9 def self.extensions %w[yml yaml] end
key_value?()
click to toggle source
(see Base.key_value?
)
# File lib/translatomatic/resource_file/yaml.rb, line 14 def self.key_value? true end
supports_variable_interpolation?()
click to toggle source
(see Base.supports_variable_interpolation?
)
# File lib/translatomatic/resource_file/yaml.rb, line 19 def self.supports_variable_interpolation? true end
Public Instance Methods
create_variable(name)
click to toggle source
(see Base#create_variable
)
# File lib/translatomatic/resource_file/yaml.rb, line 46 def create_variable(name) "%{#{name}}" end
save(target = path, options = {})
click to toggle source
(see Base#save
)
# File lib/translatomatic/resource_file/yaml.rb, line 35 def save(target = path, options = {}) return unless @data data = @data data = data.transform_keys { locale.language } if ruby_i18n? out = data.to_yaml out.sub!(/^---\n/m, '') out = comment(created_by) + "\n" + out unless options[:no_created_by] target.write(out) end
set(key, value)
click to toggle source
(see Base#set
)
Calls superclass method
Translatomatic::ResourceFile::Base#set
# File lib/translatomatic/resource_file/yaml.rb, line 24 def set(key, value) super(key, value) hash = @data path = key.to_s.split(/\./) last_key = path.pop path.each { |i| hash = (hash[i] ||= {}) } hash[last_key] = value end
variable_regex()
click to toggle source
(see Base#variable_regex
)
# File lib/translatomatic/resource_file/yaml.rb, line 51 def variable_regex /\%\s*\{.*?\}/ end
Private Instance Methods
comment(text)
click to toggle source
# File lib/translatomatic/resource_file/yaml.rb, line 75 def comment(text) "# #{text}\n" end
init()
click to toggle source
# File lib/translatomatic/resource_file/yaml.rb, line 57 def init # yaml data @data = {} end
load()
click to toggle source
# File lib/translatomatic/resource_file/yaml.rb, line 62 def load @data = ::YAML.load_file(path.to_s) || {} @properties = flatten(@data) end
ruby_i18n?()
click to toggle source
true if this resource file looks like a ruby i18n data file.
# File lib/translatomatic/resource_file/yaml.rb, line 68 def ruby_i18n? if @data && @data.length == 1 lang = @data.keys[0] Translatomatic::Locale.new(lang).valid? end end