多语言网站 poEDit 和 getText()

multi language website poEDit and getText()

我正在尝试创建一个新的多语言网站。我使用 poEDitgetText() 函数。我不知道这段代码遗漏了什么:

<?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 ");

该目录非常重要。创建这样的目录结构:

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');