2

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

__() 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? – Borek Bernard Mar 15 '12 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. – Borek Bernard Mar 15 '12 at 0:53
  • 2
    Right. If you want to use a variable, combine __() with sprintf(), such as $text = sprintf( __( 'Hello %s!', 'domain' ), $name ) – Boone Gorges Mar 15 '12 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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