Localazy: search for forbidden term ("Element" for now)
This commit is contained in:
parent
3436351619
commit
045402cf18
2 changed files with 70 additions and 0 deletions
64
tools/localazy/checkForbiddenTerms.py
Executable file
64
tools/localazy/checkForbiddenTerms.py
Executable file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from xml.dom import minidom
|
||||||
|
|
||||||
|
file = sys.argv[1]
|
||||||
|
|
||||||
|
# Arrays of forbidden terms, with exceptions for some keys
|
||||||
|
forbiddenTerms = [
|
||||||
|
[
|
||||||
|
"Element",
|
||||||
|
[
|
||||||
|
# Those 2 strings are only used in debug version
|
||||||
|
"screen_advanced_settings_element_call_base_url",
|
||||||
|
"screen_advanced_settings_element_call_base_url_description",
|
||||||
|
# only used for element.io homeserver, so it's fine
|
||||||
|
"screen_server_confirmation_message_login_element_dot_io",
|
||||||
|
# "Be in your element", will probably be changed on the forks, so we can ignore.
|
||||||
|
"screen_onboarding_welcome_title",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
content = minidom.parse(file)
|
||||||
|
|
||||||
|
errors = []
|
||||||
|
|
||||||
|
### Strings
|
||||||
|
for elem in content.getElementsByTagName('string'):
|
||||||
|
name = elem.attributes['name'].value
|
||||||
|
# Continue if value is empty
|
||||||
|
child = elem.firstChild
|
||||||
|
if child is None:
|
||||||
|
# Should not happen
|
||||||
|
continue
|
||||||
|
value = child.nodeValue
|
||||||
|
# If value contains a forbidden term, add the error to errors
|
||||||
|
for (term, exceptions) in forbiddenTerms:
|
||||||
|
if term in value and name not in exceptions:
|
||||||
|
errors.append('Forbidden term "' + term + '" in string: ' + name + ": " + value)
|
||||||
|
|
||||||
|
### Plurals
|
||||||
|
for elem in content.getElementsByTagName('plurals'):
|
||||||
|
name = elem.attributes['name'].value
|
||||||
|
for it in elem.childNodes:
|
||||||
|
if it.nodeType != it.ELEMENT_NODE:
|
||||||
|
continue
|
||||||
|
# Continue if value is empty
|
||||||
|
child = it.firstChild
|
||||||
|
if child is None:
|
||||||
|
# Should not happen
|
||||||
|
continue
|
||||||
|
value = child.nodeValue
|
||||||
|
# If value contains a forbidden term, add the error to errors
|
||||||
|
for (term, exceptions) in forbiddenTerms:
|
||||||
|
if term in value and name not in exceptions:
|
||||||
|
errors.append('Forbidden term "' + term + '" in plural: ' + name + ": " + value)
|
||||||
|
|
||||||
|
# If errors is not empty print the report
|
||||||
|
if errors:
|
||||||
|
print('Error(s) in file ' + file + ":", file=sys.stderr)
|
||||||
|
for error in errors:
|
||||||
|
print(" - " + error, file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
@ -54,6 +54,12 @@ echo "Deleting all the folders values-id..."
|
||||||
find . -type d -name 'values-id' -exec rm -rf {} 2> /dev/null \;
|
find . -type d -name 'values-id' -exec rm -rf {} 2> /dev/null \;
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
echo "Checking forbidden terms..."
|
||||||
|
find . -name 'localazy.xml' -exec ./tools/localazy/checkForbiddenTerms.py {} \;
|
||||||
|
if [[ $allFiles == 1 ]]; then
|
||||||
|
find . -name 'translations.xml' -exec ./tools/localazy/checkForbiddenTerms.py {} \;
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Removing the generated config"
|
echo "Removing the generated config"
|
||||||
rm ./tools/localazy/localazy.json
|
rm ./tools/localazy/localazy.json
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue