A platform for community discussion. Free, open, simple.
DEV: Update `i18n:check` rake task to detect invalid Markdown links (#13728)
Gerhard Schlager2a95f892afbe
diff --git a/lib/i18n/locale_file_checker.rb b/lib/i18n/locale_file_checker.rbindex 1f30f1ab66f..e818823fd8d 100644--- a/lib/i18n/locale_file_checker.rb+++ b/lib/i18n/locale_file_checker.rb@@ -8,6 +8,7 @@ class LocaleFileCheckerTYPE_UNSUPPORTED_INTERPOLATION_KEYS = 2TYPE_MISSING_PLURAL_KEYS = 3TYPE_INVALID_MESSAGE_FORMAT = 4+ TYPE_INVALID_MARKDOWN_LINK = 5def check(locale)@errors = {}@@ -20,9 +21,12 @@ class LocaleFileChecker@locale_yaml = YAML.load_file(locale_path)@reference_yaml = YAML.load_file(reference_path)+ next if @locale_yaml.blank? || @locale_yaml.first[1].blank?+check_interpolation_keyscheck_plural_keyscheck_message_format+ check_markdown_linksend@errors@@ -93,6 +97,16 @@ class LocaleFileCheckerendend+ def check_markdown_links+ traverse_hash(@locale_yaml, []) do |keys, value|+ next if value.is_a?(Array)++ if /\[.*?\]\s+\(.*?\)/.match?(value)+ add_error(keys, TYPE_INVALID_MARKDOWN_LINK, nil, pluralized: false)+ end+ end+ end+def check_plural_keysknown_parent_keys = Set.newdiff --git a/lib/tasks/i18n.rake b/lib/tasks/i18n.rakeindex 64fce0e1483..b35cce8fdc2 100644--- a/lib/tasks/i18n.rake+++ b/lib/tasks/i18n.rake@@ -6,15 +6,19 @@ require 'seed_data/topics'require 'colored2'desc "Checks locale files for errors"-task "i18n:check", [:locale] => [:environment] do |_, args|+task "i18n:check" => [:environment] do |_, args|failed_locales = []- if args[:locale].present?- if LocaleSiteSetting.valid_value?(args[:locale])- locales = [args[:locale]]- else- puts "ERROR: #{locale} is not a valid locale"- exit 1+ if args.extras.present?+ locales = []++ args.extras.each do |locale|+ if LocaleSiteSetting.valid_value?(locale)+ locales << locale+ else+ puts "ERROR: #{locale} is not a valid locale"+ exit 1+ endendelselocales = LocaleSiteSetting.supported_locales@@ -44,8 +48,10 @@ task "i18n:check", [:locale] => [:environment] do |_, args|"Missing plural keys".magentawhen LocaleFileChecker::TYPE_INVALID_MESSAGE_FORMAT"Invalid message format".yellow+ when LocaleFileChecker::TYPE_INVALID_MARKDOWN_LINK+ "Invalid markdown links".yellowend- details = error[:details] ? ": #{error[:details]}" : ""+ details = error[:details].present? ? ": #{error[:details]}" : ""puts error[:key] << " -- " << message << detailsend