discourse/script/pull_translations.rb

66 lines
2.0 KiB
Ruby
Raw Normal View History

#!/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
# List of locales that will break Discourse and need to be fixed
# by translators in Transifex.
def broken_locales
2018-08-21 23:17:42 +08:00
['ja', 'zh_TW']
end
def supported_locales
Dir.glob(expand_path('config/locales/client.*.yml'))
.map { |x| x.split('.')[-2] }
.select { |x| x != 'en' }
.sort - 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')
2016-07-27 06:15:44 +08:00
if ARGV.empty? && TranslationsManager::SUPPORTED_LOCALES != supported_locales
STDERR.puts <<~MESSAGE
2016-07-27 06:15:44 +08:00
The supported locales are out of sync.
Please update the TranslationsManager::SUPPORTED_LOCALES in translations-manager.
https://github.com/discourse/translations-manager
2016-07-27 06:15:44 +08:00
The following locales are currently supported by Discourse:
2016-07-27 06:15:44 +08:00
MESSAGE
2016-07-27 06:15:44 +08:00
STDERR.puts supported_locales.map { |l| "'#{l}'" }.join(",\n")
exit 1
2016-07-27 06:15:44 +08:00
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