Ensure that all locale files are pulled from Transifex
This commit is contained in:
parent
efbbf3167e
commit
74a855b08d
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue