DEV: Switch from Transifex to Crowdin

This commit is contained in:
Discourse Translator Bot
2020-07-16 14:00:02 +02:00
parent 1460d7957c
commit 29788f2c26
6 changed files with 49 additions and 310 deletions

View File

@ -1,91 +0,0 @@
# frozen_string_literal: true
if ARGV.empty?
puts 'Usage: ', ''
puts ' ruby plugin-translations.rb <plugins_base_dir>'
puts ' ruby plugin-translations.rb <plugins_base_dir> push (to git push)'
exit 1
end
require 'bundler'
class PluginTxUpdater
attr_reader :failed
PLUGINS = [
'discourse-adplugin',
'discourse-akismet',
'discourse-assign',
'discourse-cakeday',
'discourse-canned-replies',
'discourse-characters-required',
'discourse-chat-integration',
'discourse-checklist',
'discourse-data-explorer',
'discourse-math',
'discourse-oauth2-basic',
'discourse-patreon',
'discourse-saved-searches',
'discourse-solved',
'discourse-user-notes',
'discourse-voting'
]
def initialize(base_dir, push)
@push = !!push
@base_dir = base_dir
@failed = []
end
def perform
PLUGINS.each do |plugin_name|
plugin_dir = File.join(@base_dir, plugin_name)
Bundler.with_clean_env do
Dir.chdir(plugin_dir) do # rubocop:disable Discourse/NoChdir because this is not part of the app
puts '', plugin_dir, '-' * 80, ''
begin
system_cmd('git pull')
system_cmd('bundle update translations-manager')
system_cmd('bundle exec bin/pull_translations.rb')
system_cmd('git add config/locales/*')
system_cmd('git add Gemfile.lock') rescue true # might be gitignored
system_cmd('git add .tx/config') rescue true
system_cmd('git commit -m "Update translations"')
system_cmd('git push origin master') if @push
rescue => e
puts "Failed for #{plugin_name}. Skipping...", ''
@failed << plugin_name
end
end
end
end
end
def system_cmd(s)
rc = system(s)
raise RuntimeError.new($?) if rc != true
end
end
base_dir = File.expand_path(ARGV[0])
unless File.exists?(base_dir)
puts '', "Dir '#{base_dir}' doesn't exist."
exit 1
end
updates = PluginTxUpdater.new(base_dir, ARGV[1]&.downcase == 'push')
updates.perform
if updates.failed.empty?
puts '', "All plugins updated successfully!", ''
else
if updates.failed.size < PluginTxUpdater::PLUGINS.size
puts '', "These plugins updated successfully: ", ''
puts PluginTxUpdater::PLUGINS - updates.failed
end
puts '', "Errors were encountered while updating these plugins:", ''
puts updates.failed
end

View File

@ -1,60 +0,0 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
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
def supported_locales
Dir.glob(expand_path('config/locales/client.*.yml'))
.map { |x| x.split('.')[-2] }
.reject { |x| x.start_with?('en') }
.sort - TranslationsManager::BROKEN_LOCALES
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')
JS_LOCALE_DIR = expand_path('app/assets/javascripts/locales')
if ARGV.empty? && TranslationsManager::SUPPORTED_LOCALES != supported_locales
STDERR.puts <<~MESSAGE
The supported locales are out of sync.
Please update the TranslationsManager::SUPPORTED_LOCALES in translations-manager.
https://github.com/discourse/translations-manager
The following locales are currently supported by Discourse:
MESSAGE
STDERR.puts supported_locales.map { |l| "'#{l}'" }.join(",\n")
exit 1
end
TranslationsManager::TransifexUpdater.new(YML_DIRS, YML_FILE_PREFIXES, *ARGV).perform(tx_config_filename: TX_CONFIG)
TranslationsManager::SUPPORTED_LOCALES.each do |locale|
filename = File.join(JS_LOCALE_DIR, "#{locale}.js.erb")
next if File.exists?(filename)
File.write(filename, <<~ERB)
//= depend_on 'client.#{locale}.yml'
//= require locales/i18n
<%= JsLocaleHelper.output_locale(:#{locale}) %>
ERB
end

View File

@ -1,53 +0,0 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
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)