Class: Transdifflation::Comparer
- Inherits:
-
Object
- Object
- Transdifflation::Comparer
- Defined in:
- lib/transdifflation.rb
Overview
Implements the core
Constant Summary collapse
- NOT_TRANSLATED =
const string added to keys not translated
"**NOT_TRANSLATED** "
Instance Attribute Summary collapse
-
#has_changes ⇒ Object
readonly
Instance variable to get if changes have been detected.
Instance Method Summary collapse
-
#get_transdifflation_from_file(tag_name, path_to_yaml_relative_from_rails_root, from_locale = :en, to_locale = :es) ⇒ Object
Get Diff from YAML translation locale file from filesystem and generate differences in a file on our host.
-
#get_transdifflation_from_gem(gem_name, path_to_yaml_in_gem, from_locale = :en, to_locale = :es) ⇒ Object
Get Diff from YAML translation locale file from a gem and generate differences in a file on our host.
-
#initialize ⇒ Comparer
constructor
A new instance of Comparer.
Constructor Details
#initialize ⇒ Comparer
Returns a new instance of Comparer.
20 21 22 |
# File 'lib/transdifflation.rb', line 20 def initialize() @has_changes = false end |
Instance Attribute Details
#has_changes ⇒ Object (readonly)
Instance variable to get if changes have been detected
18 19 20 |
# File 'lib/transdifflation.rb', line 18 def has_changes @has_changes end |
Instance Method Details
#get_transdifflation_from_file(tag_name, path_to_yaml_relative_from_rails_root, from_locale = :en, to_locale = :es) ⇒ Object
Get Diff from YAML translation locale file from filesystem and generate differences in a file on our host
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/transdifflation.rb', line 64 def get_transdifflation_from_file(tag_name, path_to_yaml_relative_from_rails_root, from_locale=:en, to_locale=:es ) #default values in optional params from_locale ||= :en to_locale ||= :es #sorry, this gem was developed in Spain :) yml_source_content = YAMLReader.read_YAML_from_pathfile(path_to_yaml_relative_from_rails_root) puts "Loaded YAML content from file '#{path_to_yaml_relative_from_rails_root}'" #build the file name in our host filename_in_SRC = File.basename( path_to_yaml_relative_from_rails_root ) host_target_filename = filename_in_SRC.gsub(/-?#{from_locale}\./) do |match_s| match_s.sub("#{from_locale}", "#{to_locale}") end host_target_file = File.join( Rails.root, "config/locales/#{to_locale}", "#{tag_name}.#{host_target_filename}") if(!File.file? host_target_file) get_first_time_file(yml_source_content, host_target_file, from_locale, to_locale) else generate_diff_file(yml_source_content, host_target_file, from_locale, to_locale) end @has_changes end |
#get_transdifflation_from_gem(gem_name, path_to_yaml_in_gem, from_locale = :en, to_locale = :es) ⇒ Object
Get Diff from YAML translation locale file from a gem and generate differences in a file on our host
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/transdifflation.rb', line 30 def get_transdifflation_from_gem(gem_name, path_to_yaml_in_gem, from_locale=:en, to_locale=:es ) #default values in optional params from_locale ||= :en to_locale ||= :es #sorry, this gem was developed in Spain :) yml_gem_content = YAMLReader.read_YAML_from_gem(gem_name, path_to_yaml_in_gem) puts "Loaded YAML content from gem '#{gem_name}', file '#{path_to_yaml_in_gem}'" #build the file name in our host filename_in_gem_SRC = File.basename( path_to_yaml_in_gem ) host_target_filename = filename_in_gem_SRC.gsub(/-?#{from_locale}\./) do |match_s| match_s.sub("#{from_locale}", "#{to_locale}") end host_target_file = File.join( Rails.root, "config/locales/#{to_locale}", "#{gem_name}.#{host_target_filename}") if(!File.file? host_target_file) get_first_time_file(yml_gem_content, host_target_file, from_locale, to_locale) else generate_diff_file(yml_gem_content, host_target_file, from_locale, to_locale) end @has_changes end |