Instantly share code, notes, and snippets.

Embed
What would you like to do?
max_length check optimization
diff --git a/pontoon/checks/libraries/pontoon.py b/pontoon/checks/libraries/pontoon.py
index fb80d3f4..1f284222 100644
--- a/pontoon/checks/libraries/pontoon.py
+++ b/pontoon/checks/libraries/pontoon.py
@@ -13,6 +13,7 @@ from pontoon.sync.formats.ftl import localizable_entries
MAX_LENGTH_RE = re.compile(r'MAX_LENGTH:( *)(\d+)', re.MULTILINE)
parser = FluentParser()
+html_parser = HTMLParser.HTMLParser()
def get_max_length(comment):
@@ -38,22 +39,22 @@ def run_checks(entity, string):
resource_ext = entity.resource.format
# Prevent translations exceeding the given length limit
- max_length = get_max_length(entity.comment)
- html_parser = HTMLParser.HTMLParser()
- string_length = len(
- html_parser.unescape(
- bleach.clean(
- string,
- strip=True,
- tags=()
+ if resource_ext == 'lang':
+ max_length = get_max_length(entity.comment)
+ if max_length:
+ string_length = len(
+ html_parser.unescape(
+ bleach.clean(
+ string,
+ strip=True,
+ tags=()
+ )
+ )
)
- )
- )
-
- if max_length and string_length > max_length:
- checks['pErrors'].append(
- 'Translation too long'
- )
+ if string_length > max_length:
+ checks['pErrors'].append(
+ 'Translation too long'
+ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment