From 77fedaba8860e56631250c1c3753307df460423f Mon Sep 17 00:00:00 2001
From: Gerhard Schlager <mail@gerhard-schlager.at>
Date: Thu, 8 Nov 2018 23:58:59 +0100
Subject: [PATCH] DEV: Add script for pushing translations to Transifex

---
 script/pull_translations.rb |  8 +-----
 script/push_translations.rb | 52 +++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 7 deletions(-)
 create mode 100755 script/push_translations.rb

diff --git a/script/pull_translations.rb b/script/pull_translations.rb
index c8283486196..eb5afbd0ec5 100755
--- a/script/pull_translations.rb
+++ b/script/pull_translations.rb
@@ -12,17 +12,11 @@ def expand_path(path)
   File.expand_path("../../#{path}", __FILE__)
 end
 
-# List of locales that will break Discourse and need to be fixed
-# by translators in Transifex.
-def broken_locales
-  ['ja']
-end
-
 def supported_locales
   Dir.glob(expand_path('config/locales/client.*.yml'))
     .map { |x| x.split('.')[-2] }
     .select { |x| x != 'en' }
-    .sort - broken_locales
+    .sort - TranslationsManager::BROKEN_LOCALES
 end
 
 YML_DIRS = ['config/locales',
diff --git a/script/push_translations.rb b/script/push_translations.rb
new file mode 100755
index 00000000000..6479ab21de9
--- /dev/null
+++ b/script/push_translations.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+
+require 'bundler/inline'
+
+gemfile(true) do
+  gem 'translations-manager', git: 'https://github.com/discourse/translations-manager.git'
+end
+
+require 'translations_manager'
+
+def expand_path(path)
+  File.expand_path("../../#{path}", __FILE__)
+end
+
+YML_DIRS = ['config/locales',
+            'plugins/poll/config/locales',
+            'plugins/discourse-details/config/locales',
+            'plugins/discourse-local-dates/config/locales',
+            'plugins/discourse-narrative-bot/config/locales',
+            'plugins/discourse-nginx-performance-report/config/locales',
+            'plugins/discourse-presence/config/locales'].map { |dir| expand_path(dir) }
+YML_FILE_PREFIXES = ['server', 'client']
+TX_CONFIG = expand_path('.tx/config')
+
+puts ""
+
+resource_names = []
+languages = []
+parser = OptionParser.new do |opts|
+  opts.banner = "Usage: push_translations.rb [options]"
+
+  opts.on("-r", "--resources a,b,c", Array, "Comma separated list of resource names as found in .tx/config") { |v| resource_names = v }
+  opts.on("-l", "--languages de,fr", Array, "Comma separated list of languages") { |v| languages = v }
+  opts.on("-h", "--help") do
+    puts opts
+    exit
+  end
+end
+
+begin
+  parser.parse!
+rescue OptionParser::ParseError => e
+  STDERR.puts e.message, "", parser
+  exit 1
+end
+
+if resource_names.empty?
+  STDERR.puts "Missing argument: resources", "", parser
+  exit 1
+end
+
+TranslationsManager::TransifexUploader.new(YML_DIRS, YML_FILE_PREFIXES, resource_names, languages).perform(tx_config_filename: TX_CONFIG)