There are a few things that may go wrong.
1- To host most systems, you will need the following lines:
<?php $newlocale = setlocale(LC_MESSAGES, "sv_SE"); putenv("LANG=$newlocale"); ?>
2- On Linux, when using setlocale with LC_ALL instead of LC_MESSAGES, you need to set the locale on the server!
It can be installed with a command like this (for Ubuntu)
aptitude install language-pack-sv
Or just reconfigured with a command like this
sudo locale-gen sv_SE
3- Specify the name of the .mo files and locale directory
<?php // Use default.mo located at ./locale/LC_MESSAGES/default.mo bindtextdomain( "domain", "./locale" ); ?>
4- When mixing single and double quotes when using gettext () or _ () you will need to use two bindtextdomain!
<?php // Double quote _("Hello world") is matched bindtextdomain( "domain", "./locale" ); // Single quote _('Hello world') is matched bindtextdomain( 'domain', "./locale" ); ?>
5- Coding can be a problem in many places. If your .mo file is not in the same encoding (e.g. utf-8) than your PHP script, this may not match!
Nicolas grasset
source share