Add plugins/poll and discourse_imgur translation files to transifex

This commit is contained in:
Neil Lalonde
2014-04-24 10:11:23 -04:00
parent c52ee665b4
commit 69dee799e9
12 changed files with 83 additions and 37 deletions

View File

@@ -33,7 +33,7 @@ unless $?.success?
exit $?.exitstatus
end
yml_file_comments = <<END
YML_FILE_COMMENTS = <<END
# encoding: utf-8
#
# Never edit this file. It will be overwritten when translations are pulled from Transifex.
@@ -42,40 +42,56 @@ yml_file_comments = <<END
# https://www.transifex.com/projects/p/discourse-pt-br/
END
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']
# Change root element in yml files for some languages because Transifex uses a different
# locale code.
[['fr', 'fr_FR'], ['es', 'es_ES'], ['pt', 'pt_PT'], ['ko', 'ko_KR']].each do |ours, theirs|
LOCALE_MAPPINGS.each do |ours, theirs|
['client', 'server'].each do |base|
contents = []
file_name = File.expand_path("../../config/locales/#{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
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
end
end
end
File.open(file_name, 'w+') do |f|
f.puts(yml_file_comments, '') unless contents[0][0] == '#'
f.puts contents
File.open(file_name, 'w+') do |f|
f.puts(YML_FILE_COMMENTS, '') unless contents[0][0] == '#'
f.puts contents
end
end
end
end
(Dir.glob( File.expand_path("../../config/locales/client.*.yml", __FILE__) ).map {|x| x.split('.')[-2]}.sort - ['fr', 'es', 'pt', 'ko']).each do |locale|
# Add comments to the top of files
(ALL_LOCALES - LOCALE_MAPPINGS.map(&:first)).each do |locale|
['client', 'server'].each do |base|
file_name = File.expand_path("../../config/locales/#{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
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
end
end
end