]> git.openstreetmap.org Git - rails.git/commitdiff
Beginnings of a yaml2po script, to aid integration with places like transifex
authorThomas Wood <grand.edgemaster@gmail.com>
Wed, 3 Jun 2009 20:02:25 +0000 (20:02 +0000)
committerThomas Wood <grand.edgemaster@gmail.com>
Wed, 3 Jun 2009 20:02:25 +0000 (20:02 +0000)
The po2yaml script may come tomorrow :)

script/yaml2po [new file with mode: 0755]

diff --git a/script/yaml2po b/script/yaml2po
new file mode 100755 (executable)
index 0000000..c20c70f
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+# yaml2po, for converting RoR translation YAML to the standard gettext
+#          for eventual use with a translation site such as Transifex
+# Use:
+#  - To create a 'master' .pot
+#    yaml2po > translations.pot
+#  - To create a partucular language's .po
+#    yaml2po de > de.po
+
+require "yaml"
+
+LOCALE_DIR = File.dirname(__FILE__) + '/../config/locales/'
+
+def iterate(hash, fhash={}, path='')
+  hash.each {|key, val|
+    unless fhash.has_key? key
+     fhash[key] = {}
+    end
+    if val.is_a? Hash
+      iterate(val, fhash[key], path+key+':')
+    else
+      puts "#: #{path}#{key}"
+      puts "msgid \"#{val}\""
+      puts "msgstr \"#{fhash[key]}\""
+    end
+  }
+end
+
+language = ARGV[0]
+oth = {}
+if language
+  oth = YAML::load_file(LOCALE_DIR+language+'.yml')
+  oth = oth[language]
+end
+
+en = YAML::load_file(LOCALE_DIR+'en.yml')
+iterate(en['en'], oth)