Module: CocoaLocalize

Defined in:
lib/cocoalocalize.rb

Class Method Summary collapse

Class Method Details

.translate(path, name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cocoalocalize.rb', line 4

def translate(path,name)
  trans_path = File.join( File.dirname(__FILE__), '/translations.json' )
  trans    = JSON.parse(File.read(trans_path))
  counter  = 0
  trans.each{|language,translations|
    string_file = "#{ path }/#{ language }/MainMenu.strings"

    if File.exist?(string_file)
      puts "Processing :: #{ language }"

      main = File.read(string_file)

      translations.each{|k,v|
        if !v.nil?
          search = k.gsub(/APPLICATIONNAME/m,name)
          replace = v.gsub(/APPLICATIONNAME/m,name)

          main = main.gsub(/"#{ search }";$/m, "\"#{ replace }\";")
        end
      }

      File.open(string_file, "w") { |file| file.write(main) }

      counter += 1
    end
  }

  puts "Successfully localized project to #{ counter } languages."
end