2024 年 PHP Conference Japan

dgettext

(PHP 4, PHP 5, PHP 7, PHP 8)

dgettext覆寫目前的網域

說明

dgettext(字串 $domain, 字串 $message): 字串

dgettext() 函式允許您覆寫單個訊息查找的目前 domain

參數

domain

網域

message

訊息

傳回值

成功時傳回 字串

錯誤/例外

如果 domain 是空 字串,則會拋出 ValueError

更新日誌

版本 說明
8.4.0 現在,如果 domain 是空 字串,則會拋出 ValueError

另請參閱

  • gettext() - 在目前的網域中查找訊息

新增註釋

使用者貢獻的註釋 1 則註釋

viral at noeticsolutions dot com
18 年前
使用此函式時,請記得為您想在應用程式中使用的所有網域呼叫 bindtextdomain。例如,如果我在同一個應用程式中將 module1 和 module2 作為兩個獨立的網域,您可以執行以下操作

bindtextdomain("module1", "//path/to/my/locale/folder");
bindtextdomain("module2", "//path/to/my/locale/folder");
textdomain("module1");

echo _("Label1"); // 這個呼叫將從 module1 取得訊息
echo dgettext("module2", "Label1"); // 這個呼叫將從 module2 取得訊息

===
Viral Shah
To Top