2014-04-14 11:41:36 -04:00
|
|
|
# This script pulls translation files from Transifex and ensures they are in the format we need.
|
|
|
|
# You need the Transifex client installed.
|
|
|
|
# http://docs.transifex.com/developer/client/setup
|
|
|
|
#
|
|
|
|
# Don't use this script to create pull requests. Do translations in Transifex. The Discourse
|
|
|
|
# team will pull them in.
|
|
|
|
|
|
|
|
require 'open3'
|
|
|
|
|
|
|
|
if `which tx`.strip.empty?
|
|
|
|
puts "", "The Transifex client needs to be installed to use this script."
|
|
|
|
puts "Instructions are here: http://docs.transifex.com/developer/client/setup"
|
|
|
|
puts "", "On Mac:", ""
|
|
|
|
puts " curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py"
|
|
|
|
puts " sudo python get-pip.py"
|
|
|
|
puts " sudo pip install transifex-client", ""
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Pulling new translations...", ""
|
2014-04-16 10:35:27 -04:00
|
|
|
|
|
|
|
command = "tx pull --mode=developer #{ARGV.include?('force') ? '-f' : ''}"
|
|
|
|
|
|
|
|
Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
|
2014-04-14 11:41:36 -04:00
|
|
|
while line = stdout_err.gets
|
|
|
|
puts line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
puts ""
|
|
|
|
|
2014-04-16 10:35:27 -04:00
|
|
|
unless $?.success?
|
2014-04-14 11:41:36 -04:00
|
|
|
puts "Something failed. Check the output above.", ""
|
|
|
|
exit $?.exitstatus
|
|
|
|
end
|
|
|
|
|
2014-04-24 10:11:23 -04:00
|
|
|
YML_FILE_COMMENTS = <<END
|
2014-04-14 11:41:36 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
|
|
|
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
|
|
|
|
#
|
|
|
|
# To work with us on translations, join this project:
|
2014-05-20 12:54:19 -04:00
|
|
|
# https://www.transifex.com/projects/p/discourse-org/
|
2014-04-14 11:41:36 -04:00
|
|
|
END
|
|
|
|
|
2014-04-24 10:11:23 -04:00
|
|
|
ALL_LOCALES = Dir.glob( File.expand_path("../../config/locales/client.*.yml", __FILE__) ).map {|x| x.split('.')[-2]}.sort
|
|
|
|
|
|
|
|
LOCALE_MAPPINGS = [['fr', 'fr_FR'],
|
|
|
|
['es', 'es_ES'],
|
|
|
|
['pt', 'pt_PT'],
|
|
|
|
['ko', 'ko_KR']]
|
|
|
|
|
|
|
|
YML_DIRS = ['config/locales',
|
|
|
|
'plugins/poll/config/locales',
|
|
|
|
'vendor/gems/discourse_imgur/lib/discourse_imgur/locale']
|
|
|
|
|
2014-04-14 11:41:36 -04:00
|
|
|
# Change root element in yml files for some languages because Transifex uses a different
|
|
|
|
# locale code.
|
2014-04-24 10:11:23 -04:00
|
|
|
LOCALE_MAPPINGS.each do |ours, theirs|
|
2014-04-14 11:41:36 -04:00
|
|
|
['client', 'server'].each do |base|
|
2014-04-24 10:11:23 -04:00
|
|
|
YML_DIRS.each do |dir|
|
|
|
|
contents = []
|
|
|
|
file_name = File.expand_path("../../#{dir}/#{base}.#{ours}.yml", __FILE__)
|
|
|
|
found = false
|
|
|
|
next unless File.exists?(file_name)
|
|
|
|
File.open(file_name, 'r') do |file|
|
|
|
|
file.each_line do |line|
|
|
|
|
if found or line.strip != "#{theirs}:"
|
|
|
|
contents << line
|
|
|
|
else
|
|
|
|
contents << "#{ours}:"
|
|
|
|
found = true
|
|
|
|
end
|
2014-04-14 11:41:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-24 10:11:23 -04:00
|
|
|
File.open(file_name, 'w+') do |f|
|
|
|
|
f.puts(YML_FILE_COMMENTS, '') unless contents[0][0] == '#'
|
|
|
|
f.puts contents
|
|
|
|
end
|
2014-04-14 11:41:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-24 10:11:23 -04:00
|
|
|
# Add comments to the top of files
|
|
|
|
(ALL_LOCALES - LOCALE_MAPPINGS.map(&:first)).each do |locale|
|
2014-04-14 11:41:36 -04:00
|
|
|
['client', 'server'].each do |base|
|
2014-04-24 10:11:23 -04:00
|
|
|
YML_DIRS.each do |dir|
|
|
|
|
file_name = File.expand_path("../../#{dir}/#{base}.#{locale}.yml", __FILE__)
|
|
|
|
next unless File.exists?(file_name)
|
|
|
|
contents = File.readlines(file_name)
|
|
|
|
File.open(file_name, 'w+') do |f|
|
|
|
|
f.puts(YML_FILE_COMMENTS, '') unless contents[0][0] == '#'
|
|
|
|
f.puts contents
|
|
|
|
end
|
2014-04-14 11:41:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|