1

I am trying to add a custom string to translate in wpml, but when I use the _e(...) the content jumps outside of container

if I use like this:

echo '<h1>' . $month . ' ' . $day . '</h1>';

the html is ok:

<h1>September 29</h1>

but if I use with translation like this:

echo '<h1>' . _e($month, 'simultan') . ' ' . $day . '</h1>';

the translated string jumps out of h1:

Septembrie<h1>29</h1>

1 Answer 1

1

When you use _e your echoing the translated string. But you already have an echo so just use __(.

This is the correct code for your example

echo '<h1>' . __('September', 'simultan') . ' ' . $day . '</h1>';

If you want to add variables in your translations you should use sprintf like this:

$date = sprintf ( __('%s %d', 'simultan'), $month, $day );
echo '<h1>' . $date . '</h1>';

You might want to also have a look at date_i18n function since you are translating dates.

Reference:

Wordpress I18N

sprintf manual

Your Answer

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

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