admin管理员组

文章数量:1301534

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.

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.

Share Improve this question asked Mar 16, 2021 at 8:15 pixelngrainpixelngrain 1,3901 gold badge23 silver badges50 bronze badges 1
  • wordpress.stackexchange/questions/241589/… – cjbj Commented Mar 16, 2021 at 8:22
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: localizationLanguage string not detecting used within the function