dongweishi2028 2013-11-24 00:01
浏览 36

PHP`gettext`在Ubuntu中不起作用

I'm trying to use PHP’s get text to add multilanguage support to my website. Unsuccessful so far, and I have no idea why.

In my i18n.php file I have this:

<?php

$locale = 'pt_PT.utf8';
$locale_dir = './locale';
$domain = 'messages';

setlocale(LC_ALL, $locale);
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
bindtextdomain($domain, $locale_dir);
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);

?>

Then, in ./locale/pt_PT.utf8/LC_MESSAGES/messages.po:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION
"
"Report-Msgid-Bugs-To: 
"
"POT-Creation-Date: 2013-11-23 20:31+0000
"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>
"
"Language-Team: LANGUAGE <LL@li.org>
"
"Language: pt_PT.utf8
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"

#: index.php:12
msgid "E-mail"
msgstr "Endereço electrónico"

#: index.php:13
msgid "Password"
msgstr "Palavra-chave"

#: index.php:14
msgid "Password (again)"
msgstr "Palavra-chave (novamente)"

#: index.php:15
msgid "Login"
msgstr "Entrar"

I then generate the .mo file:

msgfmt -o ./locale/pt_PT.utf8/LC_MESSAGES/messages.mo ./locale/pt_PT.utf8/LC_MESSAGES/messages.po

It seems that php requires that the locales are installed in linux systems, so I checked with locale -a:

C
C.UTF-8
de_AT.utf8
...
en_AG
...
es_AR.utf8
...
POSIX
pt_BR.utf8
pt_PT.utf8
...

i18n.php is my first include in the index.php file, but none of the messages show. Any idea what I'm missing?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法