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.
This commit is contained in:
parent
efc4896118
commit
e428e10ed6
1 changed files with 6 additions and 3 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
# Please see LICENSE files in the repository root for full details.
|
# Please see LICENSE files in the repository root for full details.
|
||||||
|
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ file = sys.argv[1]
|
||||||
# Dict of forbidden terms, with exceptions for some String name
|
# Dict of forbidden terms, with exceptions for some String name
|
||||||
# Keys are the terms, values are the exceptions.
|
# Keys are the terms, values are the exceptions.
|
||||||
forbiddenTerms = {
|
forbiddenTerms = {
|
||||||
"Element": [
|
r"\bElement\b": [
|
||||||
# Those 2 strings are only used in debug version
|
# Those 2 strings are only used in debug version
|
||||||
"screen_advanced_settings_element_call_base_url",
|
"screen_advanced_settings_element_call_base_url",
|
||||||
"screen_advanced_settings_element_call_base_url_description",
|
"screen_advanced_settings_element_call_base_url_description",
|
||||||
|
|
@ -48,7 +49,8 @@ for elem in content.getElementsByTagName('string'):
|
||||||
value = child.nodeValue
|
value = child.nodeValue
|
||||||
# If value contains a forbidden term, add the error to errors
|
# If value contains a forbidden term, add the error to errors
|
||||||
for (term, exceptions) in forbiddenTerms.items():
|
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)
|
errors.append('Forbidden term "' + term + '" in string: "' + name + '": ' + value)
|
||||||
|
|
||||||
### Plurals
|
### Plurals
|
||||||
|
|
@ -65,7 +67,8 @@ for elem in content.getElementsByTagName('plurals'):
|
||||||
value = child.nodeValue
|
value = child.nodeValue
|
||||||
# If value contains a forbidden term, add the error to errors
|
# If value contains a forbidden term, add the error to errors
|
||||||
for (term, exceptions) in forbiddenTerms.items():
|
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)
|
errors.append('Forbidden term "' + term + '" in plural: "' + name + '": ' + value)
|
||||||
|
|
||||||
# If errors is not empty print the report
|
# If errors is not empty print the report
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue