Skip to content

A platform for community discussion. Free, open, simple.

Automatically create locale.js.erb file when adding new locale

Gerhard Schlagerbdeae17d3287
diff --git a/script/pull_translations.rb b/script/pull_translations.rb
index c3bab58ad37..21e4dc31c6b 100755
--- a/script/pull_translations.rb
+++ b/script/pull_translations.rb
@@ -28,6 +28,7 @@ YML_DIRS = ['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 TranslationsManager::SUPPORTED_LOCALES != supported_locales
STDERR.puts <<~MESSAGE
@@ -45,3 +46,14 @@ if TranslationsManager::SUPPORTED_LOCALES != supported_locales
end
TranslationsManager::TransifexUpdater.new(YML_DIRS, YML_FILE_PREFIXES, *ARGV).perform(tx_config_filename: TX_CONFIG)
+
+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