]> git.openstreetmap.org Git - rails.git/blob - script/locale/yaml2po
1837b068c71719c71dbe169f35919e2b6f2da52e
[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 language's .po from scratch
8 #    yaml2po > de.po
9 #  - To create a partucular language's .po from existing translations
10 #    yaml2po de > de.po
11
12 require "yaml"
13
14 LOCALE_DIR = File.dirname(__FILE__) + '/../../config/locales/'
15
16 def iterate(hash, fhash={}, path='')
17   hash.each {|key, val|
18     unless fhash.has_key? key
19      fhash[key] = {}
20     end
21     if val.is_a? Hash
22       iterate(val, fhash[key], path+key+':')
23     else
24       puts "msgctxt \"#{path}#{key}\""
25       puts "msgid \"#{val}\""
26       puts "msgstr \"#{fhash[key]}\""
27     end
28   }
29 end
30
31 language = ARGV[0]
32 oth = {}
33 if language
34   oth = YAML::load_file(LOCALE_DIR+language+'.yml')
35   oth = oth[language]
36 end
37
38 en = YAML::load_file(LOCALE_DIR+'en.yml')
39 iterate(en['en'], oth)