Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

__() 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.

share|improve this answer
    
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 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 Mar 15 '12 at 0:53
1  
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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