array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.gettext.php', 1 => 'gettext', ), 'up' => array ( 0 => 'ref.gettext.php', 1 => 'Gettext 関数', ), 'prev' => array ( 0 => 'function.dngettext.php', 1 => 'dngettext', ), 'next' => array ( 0 => 'function.ngettext.php', 1 => 'ngettext', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/gettext/functions/gettext.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
gettext — 現在のドメインのメッセージを参照する
message
翻訳するメッセージ。
翻訳テーブルに翻訳文字列が見つかった場合にその文字列、 あるいは見つからなかった場合に元の文字列を返します。
例1 gettext() のチェック
<?php
// ドイツ語に設定します
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// 変換テーブルの場所を指定します
bindtextdomain("myPHPApp", "./locale");
// ドメインを選択します
textdomain("myPHPApp");
// 翻訳内容は ./locale/de_DE/LC_MESSAGES/myPHPApp.mo から検索されます
// テストメッセージを出力します
echo gettext("Welcome to My PHP Application");
// あるいは、gettext() のかわりに _() も使用可能です
echo _("Have a nice day");
?>
注意:
この関数のエイリアスとして、アンダースコア文字 '_' を使用することができます。
注意:
言語を設定するだけではだめなシステムもあり、 putenv() を使って正しいロケールを定義しなければなりません。