2017-10-06 84 views
0

我想創建一個新的多語言網站。我用poEDitgetText()函數。我不知道我用這段代碼遺漏了什麼:多語言網站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

該目錄是非常導入的。創建這樣的目錄結構:

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

我有這個 「C:\ WAMP \ WWW \ loginSystemOOP /區域/ ar_JO/LC_MESSAGES/messages_ar_JO.mo」 我的文件結構是'C:\ wamp \ www \ loginSystemOOP/locale/ar_JO/LC_MESSAGES /' –