0

I am passing few big strings in my code for translation to _e(). These strings were earlier broken into multiple lines with few leading white spaces before every line to maintain indentation & readability. And since HTML ignore extra white spaces, it doesn't affect anything. But now, on passing these strings through _e(), these white spaces are also added in the string added for translation in POT file. How can I prevent these white spaces to be added for translation without removing them from code?

1

My first thought would be to wrap the string in a trim() statement:

<?php _e( trim($text), $domain ) ?>

Would this do what you are wanting it to do or did I misunderstand your question?


EDIT: On looking further at the docs, while technically you may be able to get away with passing a variable, you should not pass variables into translation functions. See the examples section in the docs.

A better bet would be to translate multiple smaller fixed text strings and then join them later, or to adjust your code so that your whitespace is in your PHP and not your string/HTML.

  • translatable strings have to be constants. – Mark Kaplun Aug 22 '17 at 1:57
  • Ummm, no. Trimming a variable does not make it any less translatable, it just changes the constant that translation will use. CONSTANTS will never translate because they cannot be redefined! – Crazycoolcam Aug 22 '17 at 12:09
  • However, I do agree with you Mark that using a variable is not how WP translations are intended to work. See doc here – Crazycoolcam Aug 22 '17 at 12:14
  • so time for you to learn something new. go and try to translate your code with poedit – Mark Kaplun Aug 22 '17 at 12:14
  • translation is not only about calling gettext at the right place, it is also about how the translator can actualy translate. with your code he will see that the string to translate is trim($text) – Mark Kaplun Aug 22 '17 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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