If there is a long string in PHP like this:

$text = "Some ... very
         long string";

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

$text = __("Some ... 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.

  • Strange, I've "merged" that long string so that it fits one line and even after that, poEdit doesn't recognize it (I've set it up according to this: weblogtoolscollection.com/archives/2007/08/27/…) The string contains HTML, {$var} reference and new lines (\n), can some of this confuse poEdit? Mar 15, 2012 at 0:52
  • Ahh it probably doesn't make sense to have a variable reference inside localized string so it's understandable why it doesn't recognize such string. My bad. Mar 15, 2012 at 0:53
  • 3
    Right. If you want to use a variable, combine __() with sprintf(), such as $text = sprintf( __( 'Hello %s!', 'domain' ), $name ) Mar 15, 2012 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.