Class: Er18Ern::Translator
- Inherits:
-
Object
- Object
- Er18Ern::Translator
- Defined in:
- lib/er18ern/improved_ermahgerd.rb
Instance Attribute Summary collapse
-
#google_translator_hax_locale_dirs ⇒ Object
Returns the value of attribute google_translator_hax_locale_dirs.
-
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
Instance Method Summary collapse
- #copy_missing_into!(place) ⇒ Object
- #en_source_yaml ⇒ Object
- #found_keys ⇒ Object
- #generate_ermahgerd! ⇒ Object
- #generate_google_translations! ⇒ Object
- #resave_en! ⇒ Object
- #save_engrish! ⇒ Object
- #save_jp! ⇒ Object
Instance Attribute Details
#google_translator_hax_locale_dirs ⇒ Object
Returns the value of attribute google_translator_hax_locale_dirs.
30 31 32 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 30 def google_translator_hax_locale_dirs @google_translator_hax_locale_dirs end |
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
30 31 32 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 30 def locales_dir @locales_dir end |
Instance Method Details
#copy_missing_into!(place) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 114 def copy_missing_into!(place) en_source_yaml["en"] output = YAML::load_file(File.("#{place}.yml", self.locales_dir)) traverse = Proc.new do |x, y| if x.is_a?(Hash) x.each do |k, v| y[k] ||= v traverse.call(v, y[k]) end end end traverse.call(en_source_yaml["en"], output[place]) File.open(File.("#{place}.yml", self.locales_dir), "w") do |fp| fp.write(output.to_yaml) end end |
#en_source_yaml ⇒ Object
32 33 34 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 32 def en_source_yaml @en_source_yaml ||= YAML::load_file(File.('en.yml', self.locales_dir)) end |
#found_keys ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 65 def found_keys @found_keys ||= begin found_keys = {} key_collector = Proc.new do |x, key_prefix| if x.is_a?(Hash) result = {} x.each do |k, v| result[k] = key_collector.call(v, "#{key_prefix}.#{k}") end result else found_keys[key_prefix] = x end end key_collector.call(en_source_yaml["en"], "") found_keys end end |
#generate_ermahgerd! ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 36 def generate_ermahgerd! traverse = Proc.new do |x, translator| if x.is_a?(Hash) result = {} x.each do |k, v| result[k] = traverse.call(v, translator) end result else translator.call(x) end end errm = {} errm['ermahgerd'] = en_source_yaml["en"] #save ermahgerd File.open(File.('ermahgerd.yml', self.locales_dir), "w") do |fp| fp.write(traverse.call(errm, lambda{|x| ImprovedErmahgerd.translate(x)}).to_yaml) end end |
#generate_google_translations! ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 84 def generate_google_translations! vals = found_keys.values.uniq.map do |val| strip_string(val) end File.open(File.('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs), "w") do |fp| fp.write(vals.join("\n---\n")) end end |
#resave_en! ⇒ Object
58 59 60 61 62 63 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 58 def resave_en! #re-save EN File.open(File.('en.yml', self.locales_dir), "w") do |fp| fp.write(en_source_yaml.to_yaml) end end |
#save_engrish! ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 94 def save_engrish! enstuff = File.read(File.('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n") engrishstuff = File.read(File.('GOOGLE_TRANSLATE_AGAIN', self.google_translator_hax_locale_dirs)).split("\n---\n") engrish = doitstuff(enstuff, found_keys, "engrish", engrishstuff) File.open(File.('engrish.yml', self.locales_dir), "w") do |fp| fp.write(engrish.to_yaml) end end |
#save_jp! ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/er18ern/improved_ermahgerd.rb', line 104 def save_jp! enstuff = File.read(File.('GOOGLE_TRANSLATE_INPUT', self.google_translator_hax_locale_dirs)).split("\n---\n") jpstuff = File.read(File.('GOOGLE_TRANSLATE_OUTPUT', self.google_translator_hax_locale_dirs)).split("\n---\n") jp = doitstuff(enstuff, found_keys, "jp", jpstuff) File.open(File.('jp.yml', self.locales_dir), "w") do |fp| fp.write(jp.to_yaml) end end |