From e428e10ed64f473aa5a5c614fb2bc994c17e6e94 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Fri, 21 Nov 2025 17:01:01 +0100 Subject: [PATCH] Use regex to check forbidden terms. (#5784) We were returning and `Elementul` as a match for the forbidden term `Element`. It now checks for the full word. --- tools/localazy/checkForbiddenTerms.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/localazy/checkForbiddenTerms.py b/tools/localazy/checkForbiddenTerms.py index d108d19e4f..e190fcea68 100755 --- a/tools/localazy/checkForbiddenTerms.py +++ b/tools/localazy/checkForbiddenTerms.py @@ -6,6 +6,7 @@ # SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. # Please see LICENSE files in the repository root for full details. +import re import sys from xml.dom import minidom @@ -14,7 +15,7 @@ file = sys.argv[1] # Dict of forbidden terms, with exceptions for some String name # Keys are the terms, values are the exceptions. forbiddenTerms = { - "Element": [ + r"\bElement\b": [ # Those 2 strings are only used in debug version "screen_advanced_settings_element_call_base_url", "screen_advanced_settings_element_call_base_url_description", @@ -48,7 +49,8 @@ for elem in content.getElementsByTagName('string'): value = child.nodeValue # If value contains a forbidden term, add the error to errors for (term, exceptions) in forbiddenTerms.items(): - if term in value and name not in exceptions: + matches = re.search(term, value) + if matches and name not in exceptions: errors.append('Forbidden term "' + term + '" in string: "' + name + '": ' + value) ### Plurals @@ -65,7 +67,8 @@ for elem in content.getElementsByTagName('plurals'): value = child.nodeValue # If value contains a forbidden term, add the error to errors for (term, exceptions) in forbiddenTerms.items(): - if term in value and name not in exceptions: + matches = re.search(term, value) + if matches and name not in exceptions: errors.append('Forbidden term "' + term + '" in plural: "' + name + '": ' + value) # If errors is not empty print the report