class BabelI18n::Adapter
Attributes
file_name[RW]
from[RW]
key[RW]
response[RW]
to[RW]
Public Class Methods
new(path, to, key)
click to toggle source
# File lib/babel_i18n/adapter.rb, line 7 def initialize(path, to, key) data = YAML::load_file(path) @from = BabelI18n::Adapter.get_language_by(data) @response = BabelI18n::Adapter.get_response(data) @file_name = BabelI18n::Adapter.get_file_name(path, to) @to = to @key = key end
Protected Class Methods
get_file_name(path, to)
click to toggle source
# File lib/babel_i18n/adapter.rb, line 35 def self.get_file_name(path, to) compost_name = path.split('/').last.split('.') compost_name.size > 2 ? "#{compost_name.first}.#{to}.yml" : "#{to}.yml" end
get_language_by(data)
click to toggle source
# File lib/babel_i18n/adapter.rb, line 40 def self.get_language_by(data) data.keys[0] end
get_response(data)
click to toggle source
# File lib/babel_i18n/adapter.rb, line 44 def self.get_response(data) data.delete(get_language_by(data)) end
Public Instance Methods
convert(response)
click to toggle source
# File lib/babel_i18n/adapter.rb, line 16 def convert(response) response.each do |key, value| convert(value) if value.is_a?(Hash) if value.is_a?(String) response[key] = BabelI18n::Base.new(value, @key).from(@from).to(@to).translate end end end
converted()
click to toggle source
# File lib/babel_i18n/adapter.rb, line 25 def converted { @to => convert(@response) } end
write_file()
click to toggle source
# File lib/babel_i18n/adapter.rb, line 29 def write_file File.open("#{@file_name}", "w") { |f| f.write converted.to_yaml } end