How to translate multi-line strings?

If there is a long string in PHP like this:

<?php
$text = "Some ... very
         very...
         long string";

Can it be localized by GetText wrapping it in __(), e.g.

<?php
$text = __("Some ... very
         very...
         long string", "domain");

? I’ve heard that GetText doesn’t support multi-line strings and indeed, when I try to scan such file in poEdit, it doesn’t find it.

How do you deal with that? WordPress source files seem to use very long lines so is that the way to go? (Obviously apart splitting the strings into multiple smaller strings which I’d rather avoid.)

Edit: the problem was that I had a variable reference in my string, e.g. __("string $someVar") which can’t be supported by GetText. My fault.

1 Answer
1

__() and the other l18n functions will handle any string you give them, including line breaks. In my experience, poEdit recognizes them just fine, but if you’re having issues, you may consider using UNIX line break escapes \n instead of actual line breaks inside the strings; in this case, be sure to use double quotes, so that they’re not rendered literally.

Leave a Comment