I am using Mpdf lib to generate PDF for the plugin I am developing. The PDF has much more tabular data that require localization.
For that, I have created a function for TH and TD as below.
function gs_pdf_th(string $text, $style = FALSE, string $class = 'header')
{
return '<th class="' . $class . '" ' . $style . '>' . __($text, 'group-shop') . '</th>';
}
This function’s problem is PO is not detecting the $text string for localization. All other text from the file where I used this function has been detected, but this one.
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
You can’t use variables in translation functions. From the internationalisation documentation:
The following example tells you what not to do
// This is incorrect do not use. _e( "Your city is $city.", 'my-theme' );The strings for translation are extracted from the source without executing the PHP associated with it. For example: The variable
$citymay be Vancouver, so your string will read"Your city is Vancouver"when the template is run but gettext won’t know what is inside the PHP variable in advance.
You need to put the value in the translation function when initially defining it.
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