chrisguk Posted April 26, 2012 Share Posted April 26, 2012 Hi, I have looked through the forum for a fix for this but I was unable to find one. Basically the code I have provided below is not giving me the correct output in other words changing the text to German. I am using an "Ubuntu" environment with Apache2 and php5 installed. I have checked that php-gettext is installed. I have also attached my .mo file (I have added the .txt extension to upload here) local.php <?php $locale = false; if (isSet($_GET["locale"])){ $locale = $_GET["locale"]; setcookie("locale", $locale, time()+60*60*24*30, "/");// save a cookie } if (!$locale && isSet($_COOKIE["locale"])){ $locale = $_COOKIE["locale"]; } putenv("LC_ALL=$locale");//needed on some systems putenv("LANGUAGE=$locale");//needed on some systems setlocale(LC_ALL, $locale); bindtextdomain("messages", $_SERVER["DOCUMENT_ROOT"]."locale"); bind_textdomain_codeset("messages", "UTF-8"); textdomain("messages"); ?> test.php <?php require_once "local.php"; echo $_SERVER["DOCUMENT_ROOT"]."locale"; //for testing ?> <html><head></head> <body> <a href='?locale=en_US'>English</a> | <a href='?locale=es_ES'>Spanish</a> | <a href='?locale=de_DE'>German</a> <br> <?php echo _("Hello World!");?><br> <p><?php echo _("My name is");?> Bob.</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/ Share on other sites More sharing options...
darkfreaks Posted April 27, 2012 Share Posted April 27, 2012 found this in the php gettext manual hope it works it said it works without having to reboot the apache or window server. <?php $gettext_domain = 'sk'; // change by language setlocale(LC_ALL, 'sk_SK.UTF-8'); // change by language, directory name sk_SK, not sk_SK.UTF-8 bindtextdomain($gettext_domain, "lang"); textdomain($gettext_domain); bind_textdomain_codeset($gettext_domain, 'UTF-8'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340952 Share on other sites More sharing options...
chrisguk Posted April 27, 2012 Author Share Posted April 27, 2012 Unfortunately that has not fixed the issue Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340980 Share on other sites More sharing options...
darkfreaks Posted April 27, 2012 Share Posted April 27, 2012 can you paste your current code so we can spot the problem? also there is a typo in your coding it is isset not isSet Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340990 Share on other sites More sharing options...
chrisguk Posted April 27, 2012 Author Share Posted April 27, 2012 Hi, Here it is: <?php $gettext_domain = 'de'; // change by language setlocale(LC_ALL, 'de_DE.UTF-8'); // change by language, directory name sk_SK, not sk_SK.UTF-8 bindtextdomain($gettext_domain, "lang"); textdomain($gettext_domain); bind_textdomain_codeset($gettext_domain, 'UTF-8'); $locale = "de_DE"; if (isSet($_GET["locale"])) $locale = $_GET["locale"]; putenv("LC_ALL=$locale"); setlocale(LC_ALL, $locale); bindtextdomain("messages", "locale"); bind_textdomain_codeset("messages", 'UTF-8'); textdomain("messages"); ?> test.php <?php require_once "local.php"; ?> <html><head></head> <body> <a href='?locale=en_US'>English</a> | <a href='?locale=es_ES'>Spanish</a> | <a href='?locale=de_DE'>German</a> <br> <?php echo _("Hello World!");?><br> <?php $world = 'world'; printf(gettext("Hello %s!"), $world); ?> <p><?php echo _("My name is");?> Bob.</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340993 Share on other sites More sharing options...
chrisguk Posted April 27, 2012 Author Share Posted April 27, 2012 I think I have fixed it, I needed to install the de_DE language pack on my server Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340996 Share on other sites More sharing options...
darkfreaks Posted April 27, 2012 Share Posted April 27, 2012 dont forget to mark topic as solved Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340997 Share on other sites More sharing options...
chrisguk Posted April 27, 2012 Author Share Posted April 27, 2012 Hi dark, Unfortunately that has not resolved the issue. I have made a final amendment to the code below, if you can figure out the issue you are a better man than me lol: <?php $gettext_domain = 'sk'; // change by language setlocale(LC_ALL, 'sk_SK.UTF-8'); // change by language, directory name sk_SK, not sk_SK.UTF-8 bindtextdomain($gettext_domain, "lang"); textdomain($gettext_domain); bind_textdomain_codeset($gettext_domain, 'UTF-8'); local.php $locale = false; if (isSet($_GET["locale"])){ $locale = $_GET["locale"]; setcookie("locale", $locale, time()+60*60*24*30, "/");// save a cookie } if (!$locale && isSet($_COOKIE["locale"])){ $locale = $_COOKIE["locale"]; } putenv("LC_ALL=$locale");//needed on some systems putenv("LANGUAGE=$locale");//needed on some systems setlocale(LC_ALL, $locale); bindtextdomain("messages", $_SERVER['DOCUMENT_ROOT']. "locale"); bind_textdomain_codeset("messages", "UTF-8"); textdomain("messages"); ?> test.php <?php require_once "local.php";?> <html><head></head> <body> <a href="?locale=en_US">English</a> | <a href="?locale=es_ES">Spanish</a> | <a href="?locale=de_DE">German</a> <br> <?php echo _("Hello World!");?><br> <p><?php echo _("My name is");?> Bob.</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1340999 Share on other sites More sharing options...
darkfreaks Posted April 27, 2012 Share Posted April 27, 2012 once again isSet is not a PHP function however isset is Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1341012 Share on other sites More sharing options...
chrisguk Posted April 27, 2012 Author Share Posted April 27, 2012 I would love to say that fixed it but it hasnt Quote Link to comment https://forums.phpfreaks.com/topic/261669-gettext-not-passing-values/#findComment-1341015 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.