I've got a website. I am looking to get gettext to operate to ensure that my British, Sweden and Norwegian sites may come up. I can not get results. What have I done wrong?

This really is my config code:

// define constants ( defualt - danish )

$lang = 'da_DA'

$lang_short = ''

$lang_prefix = 'da'

if ( isset( $_GET['lang'] ) )

situation 'en':

            $lang = 'en_EN'

            $lang_short = 'en/'

            $lang_prefix = 'en'


        situation 'se':

            $lang = 'se_SE'

            $lang_short = 'se/'

            $lang_prefix = 'se'


        situation 'no':

            $lang = 'no_NO'

            $lang_short = 'no/'

            $lang_prefix = 'no'



define( 'LANG', $lang_short )

define( 'LANG_PREFIX', $lang_prefix )

putenv("LC_ALL=". $lang )

bindtextdomain('messages', ROOT .'lang/')

And my path is /var/world wide web/rssbot.dk/lang/. Must I make chmod right, or...?

I have discovered that some gettext installs must have locale-gen run for every locale you need to use. I discovered this to be real for Ubuntu particularly. You will need to restart PHP (apache) after running locale-gen.

sudo locale-gen se_SE

sudo locale-gen no_NO

I have possess a test setup (with working locale files) that may determine whether you gettext setup is working.


//Based on your OS, putenv/setlocale/both sets a foreign language.


setlocale(LC_ALL, 'es_MX')

bindtextdomain( "su", "./locale" ) //set the locale folder for any textdomain

bind_textdomain_codeset( "su", "UTF-8" ) //set the codeset for any textdomain

textdomain( "su" ) //select a textdomain

if( gettext("Hello World!") === "Hola a todos!" ) converted it properly"

 else is not working"


You will find a couple of stuff that might fail.

1- To accomodate most systems, you'll need the next lines:


$newlocale = setlocale(LC_MESSAGES, "sv_SE")



2- On Linux, when utilizing setlocale with LC_ALL rather than LC_MESSAGES, you will have to possess the locale placed on the server!

It may be installed having a command like that one (for Ubuntu)

aptitude install language-pack-sv

Or simply re-set up having a command like that one

sudo locale-gen sv_SE

3- Specify the title of .mo files and locale directory


// Use default.mo situated at ./locale/LC_MESSAGES/default.mo

bindtextdomain( "domain", "./locale" )


4- When mixing double and single quotes while using the gettext() or _(), your will have to use two bindtextdomain!


// Double quote _("Hello world") is matched up

bindtextdomain( "domain", "./locale" )

// Single quote _('Hello world') is matched up

bindtextdomain( 'domain', "./locale" )


5- Encoding may be an problem in lots of places. In case your .mo file isn't within the same encoding (utf-8 for instance) than your PHP script, may possibly not match!