我正在尝试创建一个新的多语言网站。我使用poEDit
和getText()
函数。我不知道我错过了这段代码:
<?php
if (!function_exists("gettext"))
{
echo "gettext is not installed\n";
} else {
echo "gettext is supported\n";
}
$language = 'ar_JO';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
$domain = 'ar_JO';
bindtextdomain($domain, "./locale");
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);
echo _("HELLO_WORLD");
echo _("hi this to be translated ");
答案 0 :(得分:0)
目录非常导入。创建一个这样的目录结构:
locale/de_DE/LC_MESSAGES/messages_de_DE.mo
locale/de_DE/LC_MESSAGES/messages_de_DE.po
然后尝试这个示例代码:
<?php
$locale = 'de_DE';
//$locale = 'fr_CH';
$domain = 'messages';
$codeset = 'UTF-8';
$directory = __DIR__ . '/locale';
// Activate the locale settings
putenv('LC_ALL=' . $locale);
setlocale(LC_ALL, $locale);
// Debugging output
$file = sprintf('%s/%s/LC_MESSAGES/%s_%s.mo', $directory, $locale, $domain, $locale);
echo $file . "\n";
// Generate new text domain
$textDomain = sprintf('%s_%s', $domain, $locale);
// Set base directory for all locales
bindtextdomain($textDomain, $directory);
// Set domain codeset (optional)
bind_textdomain_codeset($textDomain, $codeset);
// File: ./locale/de_DE/LC_MESSAGES/messages_de_DE.mo
textdomain($textDomain);
// test translations
echo _('Yes');