i18n: Automatically strip Handlebars strings.

Some Handlebars strings contained whitespaces characters at their ends.
With this, such characters are removed, as well as multiple spaces
(like the ones produced by code indentation).

This also includes a couple of fixes that removes spaces that were
intentionally placed before/after the string to translate.
This commit is contained in:
Yago González
2017-03-27 21:25:43 +00:00
committed by Tim Abbott
parent 31c92cdcbc
commit e710110a9e
3 changed files with 10 additions and 7 deletions

View File

@@ -602,11 +602,11 @@ function validate_private_message() {
var context = {};
if (invalid_recipients.length === 1) {
context = {recipient: invalid_recipients.join()};
compose_error(i18n.t("The recipient __recipient__ is not valid ", context), $("#private_message_recipient"));
compose_error(i18n.t("The recipient __recipient__ is not valid", context), $("#private_message_recipient"));
return false;
} else if (invalid_recipients.length > 1) {
context = {recipients: invalid_recipients.join()};
compose_error(i18n.t("The recipients __recipients__ are not valid ", context), $("#private_message_recipient"));
compose_error(i18n.t("The recipients __recipients__ are not valid", context), $("#private_message_recipient"));
return false;
}
return true;
@@ -886,7 +886,8 @@ $(function () {
break;
case 'FileTooLarge':
// sanitization not needed as the file name is not potentially parsed as HTML, etc.
msg = "\"" + file.name + "\"" + i18n.t(" was too large; the maximum file size is 25MiB.");
var context = { file_name: file.name };
msg = i18n.t('"__file_name__" was too large; the maximum file size is 25MiB.', context);
break;
case 'REQUEST ENTITY TOO LARGE':
msg = i18n.t("Sorry, the file was too large.");

View File

@@ -57,10 +57,10 @@ IGNORED_PHRASES = [
# Fragments of larger strings
(r'Change notification settings for individual streams on your '
'<a href="/#streams">Streams page</a>.'),
(r'<p class="bot-settings-note padded-container"> Looking for our '
(r'Looking for our '
'<a href="/integrations" target="_blank">Integrations</a> or '
'<a href="{{ server_uri }}/api" target="_blank">API</a> '
'documentation? </p>'),
'documentation?'),
r'Most stream administration is done on the <a href="/#streams">Streams page</a>.',
r"one or more people...",
r"confirmation email",

View File

@@ -52,7 +52,7 @@ strip_whitespace_right = re.compile(u"(%s-?\\s*(trans|pluralize).*?-%s)\\s+" % (
strip_whitespace_left = re.compile(u"\\s+(%s-\\s*(endtrans|pluralize).*?-?%s)" % (
BLOCK_TAG_START, BLOCK_TAG_END), re.U)
regexes = ['{{#tr .*?}}(.*?){{/tr}}',
regexes = ['{{#tr .*?}}([\s\S]*?){{/tr}}', # '.' doesn't match '\n' by default
'{{t "(.*?)"\W*}}',
"{{t '(.*?)'\W*}}",
"i18n\.t\('([^\']*?)'\)",
@@ -144,6 +144,9 @@ class Command(makemessages.Command):
translation_strings = {} # type: Dict[str, str]
for regex in frontend_compiled_regexes:
for match in regex.findall(data):
match = match.strip()
match = ' '.join(line.strip() for line in match.splitlines())
match = match.replace('\n', '\\n')
translation_strings[match] = ""
return translation_strings
@@ -168,7 +171,6 @@ class Command(makemessages.Command):
continue
with open(os.path.join(dirpath, filename), 'r') as reader:
data = reader.read()
data = data.replace('\n', '\\n')
translation_strings.update(self.extract_strings(data))
dirname = os.path.join(settings.DEPLOY_ROOT, 'static/js')