Search code examples
phpwordpresstranslatepoedit

Is using echo rather than printf a trouble maker for string translation using .pot file and Poedit?


I was wondering could the use of echo in php code rather than the use of printf() be the cause of a .mo file or in general the reason why the translation files do not work at all?

For Example:

In my php code I have this line of code:
echo __('Twinkle Twinkle little star');

Which has the double underscore identifier __().

When using Poedit, I get my string displayed in the translatable strings column, so that's not an issue.

Sum up:
Could echo cause a problem with the translation even thought Poedit can index and understand that the string is there?

Thanks in advance for your time.


Solution

  • echo and printf are not related to translations. They are merely ways to output a string.

    The translating is performed by the __() function. So assuming you have your locale set to French with the proper files loaded:

    echo "Hello";
    // Hello
    echo __("Hello");
    // Bonjour
    
    printf("Hello");
    // Hello
    printf(__("Hello"));
    // Bonjour