gettext no translations showed

2019-09-19 07:20发布

问题:

I'm trying to install gettext on debian, it works perfectly on Wamp on my local computer, but not on the server. 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():

GetText Support     enabled

My php code:

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


echo _("Hello World");

greetings.po:

msgid "Hello World"
msgstr "Hallo Wereld"

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

Normally it should output "Hallo Wereld", but it is still "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.

回答1:

An idea: Try using the full path in bindtexdomain(...) without a trailing slash.

Edit/Try #2: Try running unset LANG and restarting Apache.



回答2:

Ok I just discovered how to make it.

So on Debian we do:

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)

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.



回答3:

Effectivly, a solution is to add ".utf-8" after your language name.

Another solution may be to add "locales" without ".utf8" to your debian.

I noticed this result in an OVH server (hosting company), on which your first configuration is working:

$ locale -a

en_GB

en_GB.iso88591

en_GB.iso885915

en_GB.utf8

fr_FR

fr_FR.iso88591

fr_FR.iso885915

fr_FR.utf8

and in my debian (synology) server, only:

$ locale -a

en_GB.utf8

fr_FR.utf8



标签: php linux debian