2018-09-04 17:57:20 -04:00
|
|
|
require 'i18n/locale_file_checker'
|
2019-03-18 18:13:47 -04:00
|
|
|
require 'seed_data/categories'
|
|
|
|
require 'seed_data/topics'
|
2018-09-04 17:57:20 -04:00
|
|
|
require 'colored2'
|
|
|
|
|
|
|
|
desc "Checks locale files for errors"
|
|
|
|
task "i18n:check", [:locale] => [:environment] do |_, args|
|
|
|
|
failed_locales = []
|
|
|
|
|
2018-09-04 19:04:43 -04:00
|
|
|
if args[:locale].present?
|
|
|
|
if LocaleSiteSetting.valid_value?(args[:locale])
|
|
|
|
locales = [args[:locale]]
|
2018-09-04 17:57:20 -04:00
|
|
|
else
|
|
|
|
puts "ERROR: #{locale} is not a valid locale"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
locales = LocaleSiteSetting.supported_locales
|
|
|
|
end
|
|
|
|
|
|
|
|
locales.each do |locale|
|
|
|
|
begin
|
|
|
|
all_errors = LocaleFileChecker.new.check(locale)
|
|
|
|
rescue
|
|
|
|
failed_locales << locale
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
all_errors.each do |filename, errors|
|
|
|
|
puts "", "=" * 80
|
|
|
|
puts filename.bold
|
|
|
|
puts "=" * 80
|
|
|
|
|
|
|
|
errors.each do |error|
|
2018-09-04 19:04:43 -04:00
|
|
|
message =
|
|
|
|
case error[:type]
|
2018-09-06 10:54:15 -04:00
|
|
|
when LocaleFileChecker::TYPE_MISSING_INTERPOLATION_KEYS
|
|
|
|
"Missing interpolation keys".red
|
|
|
|
when LocaleFileChecker::TYPE_UNSUPPORTED_INTERPOLATION_KEYS
|
|
|
|
"Unsupported interpolation keys".red
|
|
|
|
when LocaleFileChecker::TYPE_MISSING_PLURAL_KEYS
|
2018-09-06 11:27:17 -04:00
|
|
|
"Missing plural keys".magenta
|
|
|
|
when LocaleFileChecker::TYPE_INVALID_MESSAGE_FORMAT
|
|
|
|
"Invalid message format".yellow
|
2018-09-04 19:04:43 -04:00
|
|
|
end
|
2018-09-04 17:57:20 -04:00
|
|
|
details = error[:details] ? ": #{error[:details]}" : ""
|
|
|
|
|
|
|
|
puts error[:key] << " -- " << message << details
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-04 19:04:43 -04:00
|
|
|
failed_locales.each do |failed_locale|
|
|
|
|
puts "", "Failed to check locale files for #{failed_locale}".red
|
2018-09-04 17:57:20 -04:00
|
|
|
end
|
2018-09-06 11:27:17 -04:00
|
|
|
|
|
|
|
puts ""
|
2018-09-06 10:54:15 -04:00
|
|
|
exit 1 unless failed_locales.empty?
|
2018-09-04 17:57:20 -04:00
|
|
|
end
|
2019-03-18 16:09:13 -04:00
|
|
|
|
|
|
|
desc "Update seeded topics and categories with latest translations"
|
|
|
|
task "i18n:reseed", [:locale] => [:environment] do |_, args|
|
|
|
|
locale = args[:locale]&.to_sym
|
|
|
|
|
|
|
|
if locale.blank? || !I18n.locale_available?(locale)
|
|
|
|
puts "ERROR: Expecting rake i18n:reseed[locale]"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
SeedData::Categories.new(locale).update
|
|
|
|
SeedData::Topics.new(locale).update
|
|
|
|
end
|