Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and Gettext don't work on my server

I have a website. I'm trying to get gettext to work so that my English, Sweden and Norway sites can come up. I can't get it to work. What have I done wrong?

This is my config code:

// define constants ( defualt - danish )
$lang = 'da_DA';
$lang_short = '';
$lang_prefix = 'da';

if ( isset( $_GET['lang'] ) )
{
    switch( $_GET['lang'] )
    {
        case 'en':
            $lang = 'en_EN';
            $lang_short = 'en/';
            $lang_prefix = 'en';
            break;
        case 'se':
            $lang = 'se_SE';
            $lang_short = 'se/';
            $lang_prefix = 'se';
            break;
        case 'no':
            $lang = 'no_NO';
            $lang_short = 'no/';
            $lang_prefix = 'no';
            break;
    }
}
define( 'LANG', $lang_short );
define( 'LANG_PREFIX', $lang_prefix );

putenv("LC_ALL=". $lang );
bindtextdomain('messages', ROOT .'lang/');

And my path is /var/www/rssbot.dk/lang/. Should I make chmod right, or...?

like image 447
ParisNakitaKejser Avatar asked May 26 '10 16:05

ParisNakitaKejser


1 Answers

I've found that some gettext installs need to have locale-gen run for each locale you want to use. I found this to be true for Ubuntu in particular. You might need to restart PHP (apache) after running locale-gen.

sudo locale-gen se_SE
sudo locale-gen no_NO

I've have a test setup (with working locale files) that can determine if you gettext setup is working.

<?php

//Depending on your OS, putenv/setlocale/both will set your language.
putenv('LC_ALL=es_MX');
setlocale(LC_ALL, 'es_MX');

bindtextdomain( "su", "./locale" ); //set the locale folder for a textdomain
bind_textdomain_codeset( "su", "UTF-8" ); //set the codeset for a textdomain
textdomain( "su" ); //choose a textdomain

if( gettext("Hello World!") === "Hola a todos!" ) {
    print "We translated it correctly";
} else {
    print "Gettext setup isn't working";
}

?>
like image 123
Kendall Hopkins Avatar answered Oct 10 '22 01:10

Kendall Hopkins