How to ignore extra whitespaces in translation functions like _e?

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?

Topic xgettext localization translation plugin-development plugins Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.