Created
July 11, 2018 22:03
-
-
Save mathjazz/6ed3c0a6a6c0a53a13b381aa6fdf2926 to your computer and use it in GitHub Desktop.
max_length check optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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