我在php中構建一個網站,並使用gettext處理翻譯。到目前爲止,一切都很完美,但網站在某些時候會向用戶發送電子郵件,我無法獲得電子郵件的翻譯。使用gettext翻譯ajax調用中的電子郵件
我使用的.mo文件翻譯網站,並與我選擇了語言會話我將使用:
$lang=$_SESSION['lang'];
switch ($lang){
case 'en':
setlocale(LC_ALL, 'en_US.utf8');
putenv('LC_ALL=en_US.utf8');
bindtextdomain("estribo", "locale");
bind_textdomain_codeset("estribo", 'UTF-8');
textdomain("estribo");
break;
case 'es':
putenv('LC_ALL=es_ES.utf8');
setlocale(LC_ALL, 'es_ES.utf8');
bindtextdomain("estribo", "locale");
bind_textdomain_codeset("estribo", 'UTF-8');
textdomain("estribo");
break;
}
內部區域/ en_US.utf8/estribo.mo我所有的字符串翻譯當我在頁面的任何起訴它像這樣的正常工作:
<a href="index.php"><?echo _("Index");?></a>
它將完全翻譯這樣的rpoblem是當我做同樣的一個變量(串)的內容,我稍後會通過郵件發送而不是在屏幕上打印。
這是我的電子郵件(checkout.php)代碼:
$message = _("Some text to send via email").": \n";
//a few more lines of
$message .= _("Some more text").": \n";
mail($email, $subject, $message);
我到checkout.php的方法是通過ajax:
function() {
$.post('checkout.php', {
cart: this.cart.items,
total: this.format(this.total),
quantity: this.quantity,
shipping: $('select.shipping').val(),
tipopago: $('input.tipopago').val(),
customer: $('#checkout-form').serialize()
}, function (result) {
window.location.href = result;
});
return true;
}
一切工作和字符串在.mo文件中翻譯,但$ message變量不翻譯
「翻譯」如何? – 2012-04-20 09:47:28
使用gettext,讓我更新問題。 – 2012-04-20 09:56:21