Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/i18n/po_linter.rb')
-rw-r--r--lib/gitlab/i18n/po_linter.rb31
1 files changed, 27 insertions, 4 deletions
diff --git a/lib/gitlab/i18n/po_linter.rb b/lib/gitlab/i18n/po_linter.rb
index c0687cd9b79..e56b88dfce0 100644
--- a/lib/gitlab/i18n/po_linter.rb
+++ b/lib/gitlab/i18n/po_linter.rb
@@ -5,13 +5,14 @@ module Gitlab
class PoLinter
include Gitlab::Utils::StrongMemoize
- attr_reader :po_path, :translation_entries, :metadata_entry, :locale
+ attr_reader :po_path, :translation_entries, :metadata_entry, :locale, :html_todolist
VARIABLE_REGEX = /%{\w*}|%[a-z]/.freeze
- def initialize(po_path, locale = I18n.locale.to_s)
+ def initialize(po_path:, html_todolist:, locale: I18n.locale.to_s)
@po_path = po_path
@locale = locale
+ @html_todolist = html_todolist
end
def errors
@@ -19,7 +20,7 @@ module Gitlab
end
def validate_po
- if parse_error = parse_po
+ if (parse_error = parse_po)
return 'PO-syntax errors' => [parse_error]
end
@@ -38,7 +39,11 @@ module Gitlab
end
@translation_entries = entries.map do |entry_data|
- Gitlab::I18n::TranslationEntry.new(entry_data, metadata_entry.expected_forms)
+ Gitlab::I18n::TranslationEntry.new(
+ entry_data: entry_data,
+ nplurals: metadata_entry.expected_forms,
+ html_allowed: html_todolist.fetch(entry_data[:msgid], false)
+ )
end
nil
@@ -66,6 +71,7 @@ module Gitlab
validate_newlines(errors, entry)
validate_number_of_plurals(errors, entry)
validate_unescaped_chars(errors, entry)
+ validate_html(errors, entry)
validate_translation(errors, entry)
errors
@@ -85,6 +91,23 @@ module Gitlab
end
end
+ def validate_html(errors, entry)
+ common_message = 'contains < or >. Use variables to include HTML in the string, or the &lt; and &gt; codes ' \
+ 'for the symbols. For more info see: https://docs.gitlab.com/ee/development/i18n/externalization.html#html'
+
+ if entry.msgid_contains_potential_html? && !entry.msgid_html_allowed?
+ errors << common_message
+ end
+
+ if entry.plural_id_contains_potential_html? && !entry.plural_id_html_allowed?
+ errors << 'plural id ' + common_message
+ end
+
+ if entry.translations_contain_potential_html? && !entry.translations_html_allowed?
+ errors << 'translation ' + common_message
+ end
+ end
+
def validate_number_of_plurals(errors, entry)
return unless metadata_entry&.expected_forms
return unless entry.translated?