Ensure that all locale files are pulled from Transifex

This commit is contained in:
Gerhard Schlager 2017-09-16 22:33:00 +02:00
parent efbbf3167e
commit 74a855b08d
1 changed files with 25 additions and 10 deletions

View File

@ -8,8 +8,14 @@
require 'open3' require 'open3'
require 'psych' require 'psych'
require 'set' require 'set'
require 'fileutils'
require_relative '../lib/i18n/locale_file_walker' 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? if `which tx`.strip.empty?
puts '', 'The Transifex client needs to be installed to use this script.' puts '', 'The Transifex client needs to be installed to use this script.'
puts 'Instructions are here: http://docs.transifex.com/client/setup/' puts 'Instructions are here: http://docs.transifex.com/client/setup/'
@ -34,8 +40,23 @@ def get_languages
end end
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 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...', '' puts 'Pulling new translations...', ''
command = "tx pull --mode=developer --language=#{languages.join(',')} --force" 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/ # https://www.transifex.com/projects/p/discourse-org/
END END
YML_DIRS = ['config/locales', def yml_path_if_exists(dir, prefix, language)
'plugins/poll/config/locales', path = yml_path(dir, prefix, language)
'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__)
File.exists?(path) ? path : nil File.exists?(path) ? path : nil
end end
@ -217,7 +232,7 @@ class YamlAliasSynchronizer < LocaleFileWalker
end end
def get_english_alias_data(dir, prefix) 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 filename ? YamlAliasFinder.new.parse_file(filename) : nil
end end
@ -287,7 +302,7 @@ YML_DIRS.each do |dir|
english_alias_data = get_english_alias_data(dir, prefix) english_alias_data = get_english_alias_data(dir, prefix)
languages.each do |language| languages.each do |language|
filename = yml_path(dir, prefix, language) filename = yml_path_if_exists(dir, prefix, language)
if filename if filename
# The following methods were added to handle a bug in Transifex's yml. Should not be needed now. # The following methods were added to handle a bug in Transifex's yml. Should not be needed now.