xmltoyml.rb 1.48 KB
Newer Older
1
#!/usr/bin/env ruby
2 3
# frozen_string_literal: true

danielgrippi's avatar
danielgrippi committed
4
# Copyright (c) 2010-2011, Diaspora Inc.  This file is
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# licensed under the Affero General Public License version 3 or later.  See
# the COPYRIGHT file.


require 'rubygems'
require 'yaml'
require 'fileutils'
require 'active_model'
require 'active_model/serializers/xml'

if ARGV.length == 0
  $stderr.puts "Usage: ./script/i18n/xmltoyml.rb locale"
  $stderr.puts ""
  $stderr.puts "Imports XML-style locales"
  $stderr.puts "It expects the XML files in xml_locales/"
  $stderr.puts "You can specify the locale to import via the first parameter"
  Process.exit(1)
else
  locale = ARGV[0]
end

unless File.exists?('xml_locales')
  $stderr.puts "xml_locales directory does not exist!"
  Process.exit(2)
end

data = { "config/locales/diaspora/#{locale}.yml" => "xml_locales/#{locale}.xml",
         "config/locales/devise/devise.#{locale}.yml" => "xml_locales/devise.#{locale}.xml",
         "config/locales/javascript/javascript.#{locale}.yml" => "xml_locales/javascript.#{locale}.xml" }

danielgrippi's avatar
danielgrippi committed
35
copyright = "#   Copyright (c) 2010-2011, Diaspora Inc.  This file is\n#   licensed under the Affero General Public License version 3 or later.  See\n#   the COPYRIGHT file.\n\n"
36 37 38 39 40 41 42 43 44 45 46

data.each do |destfile, sourcefile|
  if File.exists?(sourcefile)
    source = open(sourcefile)
    dest = open(destfile, 'w')
    dest.write Hash.from_xml(source)['hash'].to_yaml.gsub('---', copyright)
    dest.close
  else
    $stderr.puts "Warning: #{sourcefile} does not exist!"
  end
end