LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-09-2005, 11:40 AM   #1
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Rep: Reputation: 15
php + gettext


I'm trying to get a php script to work with gettext for translations but it doesn't seem to be working. I have gettext installed on the local system. php is compiled with gettext support. Safe mode is set to off in php.ini. Here is the php file:
Code:
<?php
    $language = ( isset($HTTP_GET_VARS['language']) ) ? $HTTP_GET_VARS['language'] : 'en_US';
    
    putenv("LC_ALL=$language"); 
    setlocale(LC_ALL, $language);
    $domain = 'messages';
    bindtextdomain($domain, "./locale");
    textdomain($domain);
    bind_textdomain_codeset($domain, 'ISO-8859-1');
    
    header("Content-Type: text/html; charset=ISO-8859-1");
    
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>i18n test</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><!-- more ISO-8859-1 -->
</head>
<body>
<?=sprintf(gettext("Your browser says you prefer the %s language."), $_SERVER["HTTP_ACCEPT_LANGUAGE"])?><br />
<?=gettext("This is a test.")?>

<br />
<a href="index.php?language=en_US"><?=gettext("English")?></a><br />
<a href="index.php?language=es_US"><?=gettext("Spanish")?></a>

</body>
</html>
I have created the 2 required files, per locale (*.po & *.mo) and placed them in /root/directory/to/web/locale/$language/LC_MESSAGES

It always displays in english. Is the script bad? Am I missing some parameter somewhere?

Thanks

Last edited by Ateo; 11-09-2005 at 11:41 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php 5.0.5 and gettext ziggie216 Linux - Software 0 11-10-2005 02:26 PM
Compile gettext with GCJ Prop_idze Linux - Software 2 09-26-2005 10:16 AM
Awright, so who around here is a 'gettext' guru? sundialsvcs Linux - Software 0 09-12-2005 04:08 PM
horde screen blank, test.php says gettext = no posixjunkie Linux - Software 1 06-21-2004 09:49 PM
getText() problem in Java AMMullan Programming 2 04-18-2004 03:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration