This post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.
If you have a string containing a parameter, say for example someone making a statement about the number of lights, you can combine your esc_html__
function with sprintf
to switch out a placeholder with the number in a variable:
$str = sprintf(esc_html__('There are %d lights.', 'plugin-text-domain'), $number);
The %d will be contained in the string which can be translated; this is necessary as some languages may place the number in a different place of the sentence if it has a different sentence structure.