admin管理员组

文章数量:1322506

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>

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>
Share Improve this question asked Sep 16, 2020 at 10:37 Botond VajnaBotond Vajna 4714 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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

本文标签: WPML custom string translation get outside of container