X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/902a44e6303b71429441b28cdf28c5e8d474b166..ef7f3d800cbdd49b692df10d312e5fd880e2e938:/script/locale/yaml2po diff --git a/script/locale/yaml2po b/script/locale/yaml2po index 7a1750df6..22d3e78db 100755 --- a/script/locale/yaml2po +++ b/script/locale/yaml2po @@ -13,29 +13,29 @@ require "yaml" require "optparse" LOCALE_DIR = File.dirname(__FILE__) + '/../../config/locales/' -EN = YAML::load_file(LOCALE_DIR+'en.yml') +EN = YAML.load_file(LOCALE_DIR + 'en.yml') -def iterate(hash, fhash={}, path='', outfile=$stdout) +def iterate(hash, fhash = {}, path = '', outfile = $stdout) postr = '' - hash.each {|key, val| - fhash[key] = {} unless fhash.has_key? key + hash.each do |key, val| + fhash[key] = {} unless fhash.key? key if val.is_a? Hash fhash[key] = {} unless fhash[key].is_a? Hash - iterate(val, fhash[key], path+key+':', outfile) + iterate(val, fhash[key], path + key + ':', outfile) else outfile.puts "msgctxt \"#{path}#{key}\"" outfile.puts "msgid \"#{val}\"" outfile.puts "msgstr \"#{fhash[key]}\"" end - } + end end -def lang2po(lang, outfile=$stdout) +def lang2po(lang, outfile = $stdout) puts lang oth = {} - infile = LOCALE_DIR+lang+'.yml' - if File.exists? infile - oth = YAML::load_file(infile) + infile = LOCALE_DIR + lang + '.yml' + if File.exist? infile + oth = YAML.load_file(infile) oth = oth[lang] iterate(EN['en'], oth, '', outfile) else @@ -46,15 +46,17 @@ end opt = ARGV[0] if opt == '--all' # Produce .po files for all langs, and a .pot template - PO_DIR = LOCALE_DIR+'po/' + PO_DIR = LOCALE_DIR + 'po/' Dir.mkdir(PO_DIR) unless File.directory?(PO_DIR) - Dir.glob(LOCALE_DIR+"*.yml") {|filename| + Dir.glob(LOCALE_DIR + "*.yml") do |filename| lang = File.basename(filename, '.yml') - outfile = File.new(PO_DIR+"#{lang}.po", 'w') - lang2po(lang, outfile) - outfile.close - } - outfile = File.new(PO_DIR+"rails_port.pot", 'w') + unless lang == 'en' + outfile = File.new(PO_DIR + "#{lang}.po", 'w') + lang2po(lang, outfile) + outfile.close + end + end + outfile = File.new(PO_DIR + "rails_port.pot", 'w') iterate(EN['en'], {}, '', outfile) outfile.close elsif opt