Class: RailsLocaleSorter::LocaleManager
- Inherits:
-
Object
- Object
- RailsLocaleSorter::LocaleManager
- Defined in:
- lib/rails_locale_sorter.rb
Constant Summary collapse
- MERGER =
proc do |key, v1, v2| if(Hash === v1 && Hash === v2) v1.merge(v2, &MERGER) else v2 end end
Instance Attribute Summary collapse
-
#out ⇒ Object
Returns the value of attribute out.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #apply_patches(reverse_dirs = false) ⇒ Object
- #create_missing_nodes(truth = "en.yml") ⇒ Object
- #create_patches(truth = "en.yml", filters = []) ⇒ Object
-
#initialize(source_dir, out_dir) ⇒ LocaleManager
constructor
A new instance of LocaleManager.
Constructor Details
#initialize(source_dir, out_dir) ⇒ LocaleManager
Returns a new instance of LocaleManager.
43 44 45 46 47 48 |
# File 'lib/rails_locale_sorter.rb', line 43 def initialize(source_dir, out_dir) @source = source_dir @out = out_dir Dir::mkdir(@out) unless File.exists? @out end |
Instance Attribute Details
#out ⇒ Object
Returns the value of attribute out.
33 34 35 |
# File 'lib/rails_locale_sorter.rb', line 33 def out @out end |
#source ⇒ Object
Returns the value of attribute source.
33 34 35 |
# File 'lib/rails_locale_sorter.rb', line 33 def source @source end |
Instance Method Details
#apply_patches(reverse_dirs = false) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rails_locale_sorter.rb', line 75 def apply_patches(reverse_dirs = false) swap_dirs if reverse_dirs process_each_file do |patch, file, filename| target = YAML::load_file("#{@out}/#{filename}") merged = target.merge(patch, &MERGER) sort_and_write(filename, merged) end swap_dirs if reverse_dirs end |
#create_missing_nodes(truth = "en.yml") ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rails_locale_sorter.rb', line 50 def create_missing_nodes(truth = "en.yml") translations = YAML::load_file("#{@source}/#{truth}") mergee = create_blank_copy(translations) process_each_file do |hash, file, filename| unless filename == truth hash = create_missing_keys(hash, mergee) end sort_and_write(filename, hash) end end |
#create_patches(truth = "en.yml", filters = []) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rails_locale_sorter.rb', line 63 def create_patches(truth = "en.yml", filters = []) translations = YAML::load_file("#{@source}/#{truth}") process_each_file do |hash, file, filename| unless filename == truth hash = list_missing_keys(translations, hash) end sort_and_write(filename, hash, filters) end end |