0

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.

1

1 Answer 1

0

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 $city may 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.

1
  • Oh, I see... I didn't seem aware that the function won't detect the string passed using a variable. Good to know. Thanks. I can handle it now. Mar 16, 2021 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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