mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
DEV: Update i18n:check rake task to detect invalid Markdown links (#13728)
In addition to that it fixes a problem where the check failed on empty locale files and allows calling the rake task with multiple locales.
This commit is contained in:
@@ -8,6 +8,7 @@ class LocaleFileChecker
|
||||
TYPE_UNSUPPORTED_INTERPOLATION_KEYS = 2
|
||||
TYPE_MISSING_PLURAL_KEYS = 3
|
||||
TYPE_INVALID_MESSAGE_FORMAT = 4
|
||||
TYPE_INVALID_MARKDOWN_LINK = 5
|
||||
|
||||
def 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_keys
|
||||
check_plural_keys
|
||||
check_message_format
|
||||
check_markdown_links
|
||||
end
|
||||
|
||||
@errors
|
||||
@@ -93,6 +97,16 @@ class LocaleFileChecker
|
||||
end
|
||||
end
|
||||
|
||||
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_keys
|
||||
known_parent_keys = Set.new
|
||||
|
||||
|
||||
Reference in New Issue
Block a user