2018-04-28 01:01:34 +08:00
|
|
|
#!/usr/bin/env ruby
|
2014-04-14 23:41:36 +08:00
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
require 'bundler/inline'
|
2014-04-14 23:41:36 +08:00
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
gemfile(true) do
|
|
|
|
gem 'translations-manager', git: 'https://github.com/discourse/translations-manager.git'
|
2014-04-14 23:41:36 +08:00
|
|
|
end
|
2017-12-07 00:04:51 +08:00
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
require 'translations_manager'
|
2014-04-14 23:41:36 +08:00
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
def expand_path(path)
|
|
|
|
File.expand_path("../../#{path}", __FILE__)
|
2014-04-14 23:41:36 +08:00
|
|
|
end
|
|
|
|
|
2018-08-21 22:36:48 +08:00
|
|
|
# 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']
|
2018-08-21 22:36:48 +08:00
|
|
|
end
|
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
def supported_locales
|
|
|
|
Dir.glob(expand_path('config/locales/client.*.yml'))
|
|
|
|
.map { |x| x.split('.')[-2] }
|
|
|
|
.select { |x| x != 'en' }
|
2018-08-21 22:36:48 +08:00
|
|
|
.sort - broken_locales
|
2015-09-19 04:30:28 +08:00
|
|
|
end
|
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
YML_DIRS = ['config/locales',
|
|
|
|
'plugins/poll/config/locales',
|
|
|
|
'plugins/discourse-details/config/locales',
|
2018-05-04 16:13:15 +08:00
|
|
|
'plugins/discourse-local-dates/config/locales',
|
2018-04-28 01:01:34 +08:00
|
|
|
'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')
|
2018-05-29 00:51:19 +08:00
|
|
|
JS_LOCALE_DIR = expand_path('app/assets/javascripts/locales')
|
2016-07-27 06:15:44 +08:00
|
|
|
|
2018-05-30 02:57:32 +08:00
|
|
|
if ARGV.empty? && TranslationsManager::SUPPORTED_LOCALES != supported_locales
|
2018-04-28 01:01:34 +08:00
|
|
|
STDERR.puts <<~MESSAGE
|
2016-07-27 06:15:44 +08:00
|
|
|
|
2018-04-28 01:01:34 +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
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
The following locales are currently supported by Discourse:
|
2016-07-27 06:15:44 +08:00
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
MESSAGE
|
2016-07-27 06:15:44 +08:00
|
|
|
|
2018-05-30 02:57:32 +08:00
|
|
|
STDERR.puts supported_locales.map { |l| "'#{l}'" }.join(",\n")
|
2018-04-28 01:01:34 +08:00
|
|
|
exit 1
|
2016-07-27 06:15:44 +08:00
|
|
|
end
|
|
|
|
|
2018-04-28 01:01:34 +08:00
|
|
|
TranslationsManager::TransifexUpdater.new(YML_DIRS, YML_FILE_PREFIXES, *ARGV).perform(tx_config_filename: TX_CONFIG)
|
2018-05-29 00:51:19 +08:00
|
|
|
|
2018-05-30 02:57:32 +08:00
|
|
|
TranslationsManager::SUPPORTED_LOCALES.each do |locale|
|
2018-05-29 00:51:19 +08:00
|
|
|
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
|