added scripts to export/import locales to/from xml
This commit is contained in:
parent
2708b0b695
commit
4dc4c67edd
3 changed files with 83 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -30,6 +30,7 @@ public/diaspora
|
|||
spec/fixtures/*.y*ml
|
||||
spec/fixtures/*.fixture.*
|
||||
coverage/*
|
||||
xml_locales/*
|
||||
|
||||
#Documentation
|
||||
.yardoc/
|
||||
|
|
|
|||
44
script/i18n/xmltoyml.rb
Executable file
44
script/i18n/xmltoyml.rb
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env ruby
|
||||
# Copyright (c) 2011, Diaspora Inc. This file is
|
||||
# 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" }
|
||||
|
||||
copyright = "# Copyright (c) 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"
|
||||
|
||||
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
|
||||
38
script/i18n/ymltoxml.rb
Executable file
38
script/i18n/ymltoxml.rb
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env ruby
|
||||
# Copyright (c) 2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
require 'rubygems'
|
||||
require 'fileutils'
|
||||
require 'yaml'
|
||||
require 'active_model'
|
||||
require 'active_model/serializers/xml'
|
||||
|
||||
if ARGV.length == 0
|
||||
$stderr.puts "Usage: ./script/i18n/ymltoxml.rb locale"
|
||||
$stderr.puts ""
|
||||
$stderr.puts "Exports locales to XML."
|
||||
$stderr.puts "You'll find the generated files in xml_locales/"
|
||||
$stderr.puts "You can specify the locale to export via the first parameter"
|
||||
Process.exit(1)
|
||||
else
|
||||
locale = ARGV[0]
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p('xml_locales')
|
||||
|
||||
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" }
|
||||
|
||||
data.each do |sourcefile, destfile|
|
||||
if File.exists?(sourcefile)
|
||||
source = YAML.load open(sourcefile)
|
||||
dest = open(destfile, 'w')
|
||||
dest.write source.to_xml
|
||||
dest.close
|
||||
puts "Generated #{destfile}"
|
||||
else
|
||||
$stderr.puts "Warning: #{sourcefile} does not exist!"
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue