Module: I18nTranslator

Defined in:
lib/i18n_translator.rb,
lib/i18n_translator/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.create_locales(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/i18n_translator.rb', line 28

def self.create_locales(args)
  redefine_hash_to_yaml
  source = File.join(args[:dir_path], "#{args[:from].to_s}.yml")
  source_yaml = YAML.load_file(source)

  args[:to].each do |language|
    @@target_language =  language
    target_yaml = source_yaml.dup.replace(language.to_s => source_yaml[args[:from].to_s])
    target = File.join(args[:dir_path], "#{language.to_s}.yml")
  
    File.open(target, 'w+') do |file|
      file << YAML.unescape(YAML.dump(target_yaml))
    end
    args[:indicator].call(args[:dir_path], language) if args[:indicator]
  end
  
  Insider.undefine(Hash, :to_yaml)
end

.redefine_hash_to_yamlObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/i18n_translator.rb', line 47

def self.redefine_hash_to_yaml
  Insider.redefine(Hash, :to_yaml) do |opts|
    YAML::quick_emit( object_id, opts ) do |out|
      out.map( taguri, to_yaml_style ) do |map|
        sort.each do |k, v|
          v = EasyTranslate.translate(v, :to => @@target_language) unless v.is_a?(Hash)
          map.add( k, v )
        end
      end
    end
  end
end