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