]> git.openstreetmap.org Git - rails.git/blobdiff - script/locale/yaml2po
Fix some Style/StringConcatenation warnings
[rails.git] / script / locale / yaml2po
index ff5a77b26b2f9cd21dcac4400a5f2c965c0a539d..e1233fcd611e66440c9a037c50558686256477e6 100755 (executable)
 require "yaml"
 require "optparse"
 
-LOCALE_DIR = File.dirname(__FILE__) + '/../../config/locales/'
-EN = YAML::load_file(LOCALE_DIR+'en.yml')
+LOCALE_DIR = File.dirname(__FILE__) + "/../../config/locales/"
+EN = YAML.load_file("#{LOCALE_DIR}en.yml")
 
-def iterate(hash, fhash={}, path='', outfile=$stdout)
-  postr = ''
-  hash.each {|key, val|
-    fhash[key] = {} unless fhash.has_key? key
+def iterate(hash, fhash = {}, path = "", outfile = $stdout)
+  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)
+    iterate(EN["en"], oth, "", outfile)
   else
-    iterate(EN['en'], {}, '', outfile)
+    iterate(EN["en"], {}, "", outfile)
   end
 end
 
 opt = ARGV[0]
-if opt == '--all'
+if opt == "--all"
   # Produce .po files for all langs, and a .pot template
-  PO_DIR = LOCALE_DIR+'po/'
-  Dir.mkdir(PO_DIR) unless File.directory?(PO_DIR)
-  Dir.glob(LOCALE_DIR+"*.yml") {|filename|
-    lang = File.basename(filename, '.yml')
-    unless lang == 'en'
-      outfile = File.new(PO_DIR+"#{lang}.po", 'w')
+  po_dir = "#{LOCALE_DIR}po/"
+  Dir.mkdir(po_dir) unless File.directory?(po_dir)
+  Dir.glob("#{LOCALE_DIR}/*.yml") do |filename|
+    lang = File.basename(filename, ".yml")
+    unless lang == "en"
+      outfile = File.new("#{po_dir}#{lang}.po", "w")
       lang2po(lang, outfile)
       outfile.close
     end
-  }
-  outfile = File.new(PO_DIR+"rails_port.pot", 'w')
-  iterate(EN['en'], {}, '', outfile)
+  end
+  outfile = File.new("#{po_dir}rails_port.pot", "w")
+  iterate(EN["en"], {}, "", outfile)
   outfile.close
 elsif opt
   lang2po(opt)
 else
-  iterate(EN['en'])
+  iterate(EN["en"])
 end