简体   繁体   English

gettext没有翻译显示

[英]gettext no translations showed

I'm trying to install gettext on debian, it works perfectly on Wamp on my local computer, but not on the server. 我正在尝试在debian上安装gettext,它在我本地计算机上的Wamp上完美运行,但在服务器上却没有。 I did this for the install: 我这样做是为了安装:

apt-get install -V gettext

I launch this: 我发布了这个:

# apt-cache search --names-only gettext

libgettext-ant-tasks-java - Java classes for internationalization (i18n) - Ant tasks
gettext-base - GNU Internationalization utilities for the base system
gettext-doc - Documentation for GNU gettext
gettext-el - Emacs po-mode for editing gettext .po files
gettext - GNU Internationalization utilities
libgettext-activerecord-ruby-common - GetText localization for Ruby programs using ActiveRecord
libgettext-activerecord-ruby1.8 - GetText localization for Ruby programs using ActiveRecord
libgettext-activerecord-ruby1.9.1 - GetText localization for Ruby programs using ActiveRecord
libgettext-activerecord-ruby - GetText localization for Ruby programs using ActiveRecord
libgettext-commons-java - Java classes for internationalization (i18n)
libgettext-rails-ruby-doc - Gettext support for Rails 2.3
libgettext-rails-ruby1.8 - Gettext support for Rails >= 2.3
libgettext-rails-ruby - Gettext support for Rails >= 2.3
libgettext-ruby-util - Gettext utilities for ruby (dummy package)
libgettext-ruby1.8 - Gettext for ruby1.8
libgettext-ruby1.9.1 - Gettext for ruby1.9.1
libintl-gettext-ruby1.8 - Gettext wrapper for Ruby 1.8
libintl-gettext-ruby - Gettext wrapper for Ruby
liblocale-gettext-perl - Using libc functions for internationalization in Perl
liblocale-maketext-gettext-perl - Perl module bridging gettext and Maketext localization frameworks
libgettext-ocaml-dev - OCaml internationalization library
libgettext-ocaml - OCaml internationalization shared library
php-gettext - read gettext MO files directly, without requiring anything other than PHP
smarty-gettext - Gettext plugin enabling internationalization in Smarty

my phpinfo(): 我的phpinfo():

GetText Support     enabled

My php code: 我的PHP代码:

    putenv("LANG=nl_NL"); 
setlocale(LC_ALL, "nl_NL"); 
bindtextdomain("greetings", "./locale/");  
textdomain("greetings"); 


echo _("Hello World");

greetings.po: greetings.po:

msgid "Hello World"
msgstr "Hallo Wereld"

greetings.mo in: greetings.mo in:

locale/nl_NL/LC_MESSAGES/

Other informations: 其他信息:

PHP Version 5.3.3-7+squeeze3

I followed a lot of tutorials, but none of them works, the last one was http://www.aota.net/forums/showthread.php?threadid=10615 我遵循了很多教程,但没有一个是有效的,最后一个是http://www.aota.net/forums/showthread.php?threadid=10615

Normally it should output "Hallo Wereld", but it is still "Hello World". 通常它应该输出“Hallo Wereld”,但它仍然是“Hello World”。 I restarted the server and the translation has been made since a while so it's not a cache problem. 我重新启动了服务器并且已经进行了一段时间的翻译,所以这不是缓存问题。

Thank you very much. 非常感谢你。

An idea: Try using the full path in bindtexdomain(...) without a trailing slash. 一个想法:尝试使用bindtexdomain(...)的完整路径而不使用尾部斜杠。

Edit/Try #2: Try running unset LANG and restarting Apache. 编辑/尝试#2:尝试运行未unset LANG并重新启动Apache。

Ok I just discovered how to make it. 好的,我刚刚发现了如何制作它。

So on Debian we do: 所以在Debian上我们做:

dpkg-reconfigure locales

then we pick the languages we need. 然后我们选择我们需要的语言。

and the code must have exactly the same writing then the when we type # locale -a (.utf8 if you chose that one) 并且代码必须具有完全相同的写作然后我们输入#locale -a(.utf8,如果你选择那个)

putenv('LC_ALL=nl_NL.utf8');
setlocale(LC_ALL, "nl_NL.utf8");
bindtextdomain("greetings", "./locale");
textdomain("greetings");


echo gettext("Hello World");

Strange but it works. 奇怪,但它的工作原理。

Effectivly, a solution is to add ".utf-8" after your language name. 有效地,解决方案是在您的语言名称后添加“.utf-8”。

Another solution may be to add "locales" without ".utf8" to your debian. 另一个解决方案可能是在没有“.utf8”的情况下为你的debian添加“locales”。

I noticed this result in an OVH server (hosting company), on which your first configuration is working: 我在OVH服务器(托管公司)中注意到了这个结果,您的第一个配置正在运行:

$ locale -a $ locale -a

en_GB EN_GB

en_GB.iso88591 en_GB.iso88591

en_GB.iso885915 en_GB.iso885915

en_GB.utf8 en_GB.utf8

fr_FR fr_FR目录

fr_FR.iso88591 fr_FR.iso88591

fr_FR.iso885915 fr_FR.iso885915

fr_FR.utf8 fr_FR.utf8

and in my debian (synology) server, only: 在我的debian(synology)服务器中,只有:

$ locale -a $ locale -a

en_GB.utf8 en_GB.utf8

fr_FR.utf8 fr_FR.utf8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM