From 74a855b08d38681d00f4c37e1e84dd96a7e36a35 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager <mail@gerhard-schlager.at> Date: Sat, 16 Sep 2017 22:33:00 +0200 Subject: [PATCH] Ensure that all locale files are pulled from Transifex --- script/pull_translations.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/script/pull_translations.rb b/script/pull_translations.rb index 2acb4d2dab1..a739b0da47f 100644 --- a/script/pull_translations.rb +++ b/script/pull_translations.rb @@ -8,8 +8,14 @@ require 'open3' require 'psych' require 'set' +require 'fileutils' require_relative '../lib/i18n/locale_file_walker' +YML_DIRS = ['config/locales', + 'plugins/poll/config/locales', + 'plugins/discourse-narrative-bot/config/locales'] +YML_FILE_PREFIXES = ['server', 'client'] + if `which tx`.strip.empty? puts '', 'The Transifex client needs to be installed to use this script.' puts 'Instructions are here: http://docs.transifex.com/client/setup/' @@ -34,8 +40,23 @@ def get_languages end end +def yml_path(dir, prefix, language) + path = "../../#{dir}/#{prefix}.#{language}.yml" + File.expand_path(path, __FILE__) +end + languages = get_languages.select { |x| x != 'en' }.sort +# ensure that all locale files exists. tx doesn't create missing locale files during pull +YML_DIRS.each do |dir| + YML_FILE_PREFIXES.each do |prefix| + languages.each do |language| + filename = yml_path(dir, prefix, language) + FileUtils.touch(filename) unless File.exists?(filename) + end + end +end + puts 'Pulling new translations...', '' command = "tx pull --mode=developer --language=#{languages.join(',')} --force" @@ -60,14 +81,8 @@ YML_FILE_COMMENTS = <<END # https://www.transifex.com/projects/p/discourse-org/ END -YML_DIRS = ['config/locales', - 'plugins/poll/config/locales', - 'plugins/discourse-narrative-bot/config/locales'] -YML_FILE_PREFIXES = ['server', 'client'] - -def yml_path(dir, prefix, language) - path = "../../#{dir}/#{prefix}.#{language}.yml" - path = File.expand_path(path, __FILE__) +def yml_path_if_exists(dir, prefix, language) + path = yml_path(dir, prefix, language) File.exists?(path) ? path : nil end @@ -217,7 +232,7 @@ class YamlAliasSynchronizer < LocaleFileWalker end def get_english_alias_data(dir, prefix) - filename = yml_path(dir, prefix, 'en') + filename = yml_path_if_exists(dir, prefix, 'en') filename ? YamlAliasFinder.new.parse_file(filename) : nil end @@ -287,7 +302,7 @@ YML_DIRS.each do |dir| english_alias_data = get_english_alias_data(dir, prefix) languages.each do |language| - filename = yml_path(dir, prefix, language) + filename = yml_path_if_exists(dir, prefix, language) if filename # The following methods were added to handle a bug in Transifex's yml. Should not be needed now.