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>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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:
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0