]> git.openstreetmap.org Git - rails.git/blob - script/locale/yaml2po
Don't set the Status header - it is set automatically by the FastCGI code
[rails.git] / script / locale / yaml2po
1 #!/usr/bin/env ruby
2 # yaml2po, for converting RoR translation YAML to the standard gettext
3 #          for eventual use with a translation site such as Transifex
4 # Use:
5 #  - To create a 'master' .pot
6 #    yaml2po > translations.pot
7 #  - To create a partucular language's .po
8 #    yaml2po de > de.po
9
10 require "yaml"
11
12 LOCALE_DIR = File.dirname(__FILE__) + '/../../config/locales/'
13
14 def iterate(hash, fhash={}, path='')
15   hash.each {|key, val|
16     unless fhash.has_key? key
17      fhash[key] = {}
18     end
19     if val.is_a? Hash
20       iterate(val, fhash[key], path+key+':')
21     else
22       puts "#: #{path}#{key}"
23       puts "msgid \"#{val}\""
24       puts "msgstr \"#{fhash[key]}\""
25     end
26   }
27 end
28
29 language = ARGV[0]
30 oth = {}
31 if language
32   oth = YAML::load_file(LOCALE_DIR+language+'.yml')
33   oth = oth[language]
34 end
35
36 en = YAML::load_file(LOCALE_DIR+'en.yml')
37 iterate(en['en'], oth)