i18n with gettext but without the locale hassle?
Zend_Translate works with it
http://framework.zend.com/manual/en/zend.translate.adapter.html#zend.translate.adapter.gettext
Use PHP Gettext without having to install locales
Here is the solution:
$lang = 'de'; //debug
setlocale( LC_ALL, 'C.UTF-8' );
bindtextdomain( 'default', PATH . "/locale/$lang" );
bind_textdomain_codeset( 'default', 'UTF-8' );
textdomain( 'default' );
The only difference between that and the example I posted at the bottom of my answer is that it uses C.UTF-8
not just C
.
I'll be doing more testing of this, and if it works cross-platform, and will update this answer if I find out anything else.
How to enable locale en_EN on centOS to get i18n gettext working
I wouldn't recommend anyone using setlocale()
and gettext()
for localization in PHP (there are some serious issues that will drive any developer nuts). But anyway, there is no en_EN locale. The identifier before the underscore is the language (en = English), the identifier after the underscore is the country (EN = ???). You probably should be using en_US, en_GB, or something else.
gettext working locally, but not on the host server
gettext will only support the installed locales. If you have a shell on your hosting provider you should run 'locale -a' to see a list of installed locales. You may need to contact your hosting provider to have them install the necessary language pack for pl.
i18n/gettext : setlocale configuration in web applications
This is not a qualified answer to your question, and I'm not saying using gettext is bad - I never worked enough with it to have a really deep opinion on it - but I decided to leave gettext alone because of its complexity and massive unpredictability on different platforms with different locales. I posted a question looking for alternatives here and while there is not really much around, the Zend_translate package seems to be worth a look. I haven't got around to it myself yet.
If you work with gettext, be sure to check out the PHP Manual User Contributed Notes on Gettext.
PHP Localization Question
I recommend you take a look at Zend_translate, Zend_locale and Zend_Date. I'm only starting to dabble with them myself, but to me, they already look like a really good, clean and modern solution to internationalization, in contrast to the chaos that is gettext.
The introduction to Zend_translate lists a number of strong arguments why to choose it (or something similar) over gettext.
In multilingual applications, the
content must be translated into
several languages and display content
depending on the user's language. PHP
offers already several ways to handle
such problems, however the PHP
solution has some problems:Inconsistent API: There is no single API for the different source
formats. The usage of gettext for
example is very complicated.PHP supports only gettext and native array: PHP itself offers only
support for array or gettext. All
other source formats have to be coded
manually, because there is no native
support.No detection of the default language: The default language of the
user cannot be detected without deeper
knowledge of the backgrounds for the
different web browsers.Gettext is not thread-safe: PHP's gettext library is not thread
safe, and it should not be used in a
multithreaded environment. This is due
to problems with gettext itself, not
PHP, but it is an existing problem.
Is there a way to access the locale used by gettext under windows?
Turns out the "gl_locale_name" function was not part of gettext directly, but rather part of gnulib - http://www.gnu.org/software/gnulib. I just discovered the package today.
So getting the infamous localename.h header in my project was a matter of
gnulib-tool --import localename
Then the gl_locale_name function works just fine when cross-compiling.
Thanks to everyone for the answers !
Related Topics
Mysqli Commands Out of Sync; You Can't Run This Command Now
How to Get a PHP Value from an HTML Form
How to Disable PHP Magic Quotes at Runtime
A Method of Selecting Random Characters from Given String
Pass Value from HTML Form to PHP Without Submitting the Form
Why Composer Can Not Find My Brand New Package on Packagist.Org
PHP $_Get and $_Post Undefined Problem
Laravel Access Denied for User 'Root'@'Localhost' (Using Password: Yes) in Laravel 4.2
Maximum Length of Generated Hash When Using Password_Hash
PHP Domdocument Getting Attribute of Tag
Saving Div Contents or Canvas as Image
Finding Common Value Among Sub-Arrays in a Multidimensional Array
Send Email by Email Class in Codeigniter with Gmail
PHP Session Variables Not Preserved with Ajax
Why Is the Semicolon Optional in the Last Statement in PHP