簡體   English   中英

參數為變量時如何在php echo調用中進行語言翻譯

[英]How to do language translation in php echo call when parameter is a variable

我繼承了一個wordpress插件,其中一個變量保存要顯示的html字符串的值。

例如,

$html=$html."<H1>Enter Your Account Information </h1>";
$html=$html."<h2>Your First Name</h2>";
$html=$html.  .... (more strings like above)  ....
echo $html

整個插件具有這種類型的構造,而不是

 echo '<H1>Enter Your Account Information </h1>';

可以輕松更改為:

echo '<h1>' . __('Enter Your Account Information', 'myplugin') . '</h1>';

有沒有辦法按照當前實施的方式進行翻譯?

還是我必須更改它以便它立即回顯到屏幕並跳過構建$ html變量?

提前致謝。

您可以將String與翻譯一起存儲

$html .= '<h1>' . __('Enter Your Account Information', 'myplugin') . '</h1>';
$html .= '<h2>' . __('Your First Name', 'myplugin') . '</h2>';

以后您可以像這樣echo$html變量

echo $html;

注意:如果要立即回顯翻譯,請使用:

 _e('Enter Your Account Information', 'myplugin');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM