Search code examples
pythongettext

Pygettext - Gettext over multiple lines


I want to translate a string with PyGettext. The problems is, the string is very long. So I had to split it into multiple lines:

print _("Some text... foo bar foo bar foo bar ..... blah blah" + \
        "More text")

But I get the following error message:

*** ../myApp:1: Seen unexpected token "+"

How can I write a string like that? I don't want to write it in one line because the code will look terrible. I also don't want to use three quotation marks (""") because the translation will be messed up with a way too many spaces....


Solution

  • The Python compiler concatenates adjacent string literals.

    print _("Some text... foo bar foo bar foo bar ..... blah blah"
            "More text")
    

    ...

    >>> print 'a' 'b'
    ab