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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /lib/gitlab/i18n/translation_entry.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/gitlab/i18n/translation_entry.rb')
-rw-r--r--lib/gitlab/i18n/translation_entry.rb36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/gitlab/i18n/translation_entry.rb b/lib/gitlab/i18n/translation_entry.rb
index 19c10b2e402..25a45332d27 100644
--- a/lib/gitlab/i18n/translation_entry.rb
+++ b/lib/gitlab/i18n/translation_entry.rb
@@ -4,12 +4,14 @@ module Gitlab
module I18n
class TranslationEntry
PERCENT_REGEX = /(?:^|[^%])%(?!{\w*}|[a-z%])/.freeze
+ ANGLE_BRACKET_REGEX = /[<>]/.freeze
- attr_reader :nplurals, :entry_data
+ attr_reader :nplurals, :entry_data, :html_allowed
- def initialize(entry_data, nplurals)
+ def initialize(entry_data:, nplurals:, html_allowed:)
@entry_data = entry_data
@nplurals = nplurals
+ @html_allowed = html_allowed
end
def msgid
@@ -83,8 +85,38 @@ module Gitlab
string =~ PERCENT_REGEX
end
+ def msgid_contains_potential_html?
+ contains_angle_brackets?(msgid)
+ end
+
+ def plural_id_contains_potential_html?
+ contains_angle_brackets?(plural_id)
+ end
+
+ def translations_contain_potential_html?
+ all_translations.any? { |translation| contains_angle_brackets?(translation) }
+ end
+
+ def msgid_html_allowed?
+ html_allowed.present?
+ end
+
+ def plural_id_html_allowed?
+ html_allowed.present? && html_allowed['plural_id'] == plural_id
+ end
+
+ def translations_html_allowed?
+ msgid_html_allowed? && html_allowed['translations'].present? && all_translations.all? do |translation|
+ html_allowed['translations'].include?(translation)
+ end
+ end
+
private
+ def contains_angle_brackets?(string)
+ string =~ ANGLE_BRACKET_REGEX
+ end
+
def translation_entries
@translation_entries ||= entry_data.fetch_values(*translation_keys)
.reject(&:empty?)