Files
element-x-android/tools/localazy/checkForbiddenTerms.py
T
Jorge Martin Espinosa bbb83c2ff0 Localazy: improve search, parallelize checks (#7261)
* Remove no longer temporary string

These are now in localazy and the sync strings CI flow was failing because we have 2 conflicting values in `temporary.xml` and `localazy.xml`

* Use the right placeholder value in `screen_local_network_opt_in_subtitle`

* Localazy: improve search, parallelize checks

The search for XML files has been narrowed down and it's several times faster now, and processing the files is now done in parallel

* Improve script to also find and delete previous files

Also add the option of having a `-v|--verbose` flag to print which files we're modifying

* Use `LocalBuildMeta` to get the app name inside `LocalNetworkPermissionDialogView`

* Allow finding all the forbidden terms in the strings and translations and then return an error exit code instead of a success one

---------

Co-authored-by: ElementBot <android@element.io>
2026-07-27 15:12:53 +02:00

88 lines
3.2 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2025 Element Creations Ltd.
# Copyright 2024, 2025 New Vector Ltd.
#
# 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
file = sys.argv[1]
# Dict of forbidden terms, with exceptions for some String name
# Keys are the terms, values are the exceptions.
forbiddenTerms = {
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",
# 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",
# Contains "Element Call"
"screen_incoming_call_subtitle_android",
"call_invalid_audio_device_bluetooth_devices_disabled",
# Contains "Element X"
"screen_room_timeline_legacy_call",
# We explicitly want to mention Element Pro in these 2:
"screen_change_server_error_element_pro_required_title",
"screen_change_server_error_element_pro_required_message",
# Contains "Element Classic"
"screen_missing_key_backup_open_element_classic",
"screen_missing_key_backup_step_1",
# These are notification sound names
"screen_notification_settings_sound_element_default",
"screen_notification_settings_sound_element_fade",
# This contains the word 'element' in some languages
"screen_media_upload_preview_item_count",
]
}
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.items():
matches = re.search(term, value)
if matches 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.items():
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
if errors:
print('Error(s) in file ' + file + ":", file=sys.stderr)
for error in errors:
print(" - " + error, file=sys.stderr)
sys.exit(1)