mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							31c92cdcbc
						
					
				
				
					commit
					e710110a9e
				
			@@ -602,11 +602,11 @@ function validate_private_message() {
 | 
				
			|||||||
    var context = {};
 | 
					    var context = {};
 | 
				
			||||||
    if (invalid_recipients.length === 1) {
 | 
					    if (invalid_recipients.length === 1) {
 | 
				
			||||||
        context = {recipient: invalid_recipients.join()};
 | 
					        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;
 | 
					        return false;
 | 
				
			||||||
    } else if (invalid_recipients.length > 1) {
 | 
					    } else if (invalid_recipients.length > 1) {
 | 
				
			||||||
        context = {recipients: invalid_recipients.join()};
 | 
					        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 false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
@@ -886,7 +886,8 @@ $(function () {
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case 'FileTooLarge':
 | 
					        case 'FileTooLarge':
 | 
				
			||||||
            // sanitization not needed as the file name is not potentially parsed as HTML, etc.
 | 
					            // 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;
 | 
					            break;
 | 
				
			||||||
        case 'REQUEST ENTITY TOO LARGE':
 | 
					        case 'REQUEST ENTITY TOO LARGE':
 | 
				
			||||||
            msg = i18n.t("Sorry, the file was too large.");
 | 
					            msg = i18n.t("Sorry, the file was too large.");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,10 +57,10 @@ IGNORED_PHRASES = [
 | 
				
			|||||||
    # Fragments of larger strings
 | 
					    # Fragments of larger strings
 | 
				
			||||||
    (r'Change notification settings for individual streams on your '
 | 
					    (r'Change notification settings for individual streams on your '
 | 
				
			||||||
     '<a href="/#streams">Streams page</a>.'),
 | 
					     '<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="/integrations" target="_blank">Integrations</a> or '
 | 
				
			||||||
     '<a href="{{ server_uri }}/api" target="_blank">API</a> '
 | 
					     '<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'Most stream administration is done on the <a href="/#streams">Streams page</a>.',
 | 
				
			||||||
    r"one or more people...",
 | 
					    r"one or more people...",
 | 
				
			||||||
    r"confirmation email",
 | 
					    r"confirmation email",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)" % (
 | 
					strip_whitespace_left = re.compile(u"\\s+(%s-\\s*(endtrans|pluralize).*?-?%s)" % (
 | 
				
			||||||
                                   BLOCK_TAG_START, BLOCK_TAG_END), re.U)
 | 
					                                   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*}}',
 | 
				
			||||||
           "{{t '(.*?)'\W*}}",
 | 
					           "{{t '(.*?)'\W*}}",
 | 
				
			||||||
           "i18n\.t\('([^\']*?)'\)",
 | 
					           "i18n\.t\('([^\']*?)'\)",
 | 
				
			||||||
@@ -144,6 +144,9 @@ class Command(makemessages.Command):
 | 
				
			|||||||
        translation_strings = {} # type: Dict[str, str]
 | 
					        translation_strings = {} # type: Dict[str, str]
 | 
				
			||||||
        for regex in frontend_compiled_regexes:
 | 
					        for regex in frontend_compiled_regexes:
 | 
				
			||||||
            for match in regex.findall(data):
 | 
					            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] = ""
 | 
					                translation_strings[match] = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return translation_strings
 | 
					        return translation_strings
 | 
				
			||||||
@@ -168,7 +171,6 @@ class Command(makemessages.Command):
 | 
				
			|||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
                with open(os.path.join(dirpath, filename), 'r') as reader:
 | 
					                with open(os.path.join(dirpath, filename), 'r') as reader:
 | 
				
			||||||
                    data = reader.read()
 | 
					                    data = reader.read()
 | 
				
			||||||
                    data = data.replace('\n', '\\n')
 | 
					 | 
				
			||||||
                    translation_strings.update(self.extract_strings(data))
 | 
					                    translation_strings.update(self.extract_strings(data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        dirname = os.path.join(settings.DEPLOY_ROOT, 'static/js')
 | 
					        dirname = os.path.join(settings.DEPLOY_ROOT, 'static/js')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user