Jameu Lukasli1
Jameu Lukasli1

Reputation: 517

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.

Upvotes: 1

Views: 176

Answers (1)

rickdenhaan
rickdenhaan

Reputation: 11328

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

Upvotes: 2

Related Questions