need help with gettext i18n

This is a discussion on need help with gettext i18n within the PHP General forums, part of the PHP Programming Forums category; Hi there, I am trying to get I18n support working on my site. To do this I have isntalled gettext. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-24-2003
Merlin
 
Posts: n/a
Default need help with gettext i18n

Hi there,

I am trying to get I18n support working on my site. To do this I have
isntalled gettext.

Somehow the translation does not work. I did everything the examples
explained, but I do stillg get en text.

Here is what I did.

1. I creaed a test file:

<?php

// I18N support information here
$language = 'de';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "/home/www/mydocs/x_dev/sprachen/gettext/locale");
textdomain($domain);
echo gettext("A string to be translated would go here");

?>

2. I extracted the text via command line:
xgettext -a test.php

3. I translated it and created a mo file with poedit (editor)

4. I moved the files into a de directory


/locale
/de
/LC_MESSAGES
messages.po


When I load the php file in the browser it still gives me the entlish
language.

Has anybody an idea on what I am doing wrong?

Thank you for any help on that,

Merlin
Reply With Quote
  #2 (permalink)  
Old 11-25-2003
Tom Rogers
 
Posts: n/a
Default Re: [PHP] need help with gettext i18n

Hi,

Tuesday, November 25, 2003, 2:25:33 AM, you wrote:
M> Hi there,

M> I am trying to get I18n support working on my site. To do this I have
M> isntalled gettext.

M> Somehow the translation does not work. I did everything the examples
M> explained, but I do stillg get en text.

M> Here is what I did.

M> 1. I creaed a test file:

M> <?php

M> // I18N support information here
M> $language = 'de';
M> putenv("LANG=$language");
M> setlocale(LC_ALL, $language);
M> // Set the text domain as 'messages'
M> $domain = 'messages';
M> bindtextdomain($domain, "/home/www/mydocs/x_dev/sprachen/gettext/locale");
M> textdomain($domain);
M> echo gettext("A string to be translated would go here");

?>>

M> 2. I extracted the text via command line:
M> xgettext -a test.php

M> 3. I translated it and created a mo file with poedit (editor)

M> 4. I moved the files into a de directory


M> /locale
M> /de
M> /LC_MESSAGES
M> messages.po


M> When I load the php file in the browser it still gives me the entlish
M> language.

M> Has anybody an idea on what I am doing wrong?

M> Thank you for any help on that,

M> Merlin


If on linux you may need to generate the right files with something like:

localedef -ci de_DE -f ISO_8859-1:1987 de_DE

Then restart apache as it caches locale info I think
--
regards,
Tom
Reply With Quote
  #3 (permalink)  
Old 11-25-2003
Eugene Lee
 
Posts: n/a
Default Re: [PHP] $ of variables, php, mysql

On Mon, Nov 24, 2003 at 09:42:30PM -0800, Joffrey Leevy wrote:
:
: Would appreciate in anyone can help me.

Some more code would be helpful.

: Let's say I do a query in php, eg. $query = "select
: shed from structure"; With the mysql_fetch_array
: function and a loop I could see all the values stored
: in the column, shed, using the command: echo $shed;

$query = "select shed from structure";
$result = mysql_query($query);
while (($row = mysql_fetch_array($result)) !== false)
{
echo $row['shed'];
}

: Let's say now that I am carrying over a variable from
: a form called $form where $form = shed. I can still
: say $query = "select $form from structure"; because
: $form = shed.

Try using more variables to make life a little easier to parse:

$colname = $_FORM['form']
$query = "select {$colname} from structure";
$result = mysql_query($query);
while (($row = mysql_fetch_array($result)) !== false)
{
echo $row[$colname];
}

: The problem I have now is with the strings and how do
: I see my column values.

Use better variable names. And avoid register_globals.
Reply With Quote
  #4 (permalink)  
Old 11-25-2003
Marek Kilimajer
 
Posts: n/a
Default Re: [PHP] $ of variables, php, mysql

Eugene Lee wrote:
> Try using more variables to make life a little easier to parse:
>
> $colname = $_FORM['form']
> $query = "select {$colname} from structure";
> $result = mysql_query($query);
> while (($row = mysql_fetch_array($result)) !== false)
> {
> echo $row[$colname];
> }
>


Very dangerous. $colname can be anything, e.g. "mysql.user.password
colname FROM mysql.user #"
Reply With Quote
  #5 (permalink)  
Old 11-25-2003
Eugene Lee
 
Posts: n/a
Default Re: [PHP] $ of variables, php, mysql

On Tue, Nov 25, 2003 at 11:38:27AM +0100, Marek Kilimajer wrote:
: Eugene Lee wrote:
: >
: >Try using more variables to make life a little easier to parse:
: >
: > $colname = $_FORM['form']
: > $query = "select {$colname} from structure";
: > $result = mysql_query($query);
: > while (($row = mysql_fetch_array($result)) !== false)
: > {
: > echo $row[$colname];
: > }
: >
:
: Very dangerous. $colname can be anything, e.g. "mysql.user.password
: colname FROM mysql.user #"

I wrote it out this way because: the other user provided no source code,
I wanted to show working code, it was late and I didn't feel like adding
anything to secure against intrusions like SQL injection attacks. For
the sake of completeness, redo the first line above as:

$colname = mysql_escape_string($_FORM['form']);
Reply With Quote
  #6 (permalink)  
Old 11-25-2003
Joffrey Leevy
 
Posts: n/a
Default Re: [PHP] $ of variables, php, mysql

Hey thanks guys. Problem solved.



--- Eugene Lee <list-php-1@fsck.net> wrote:
> On Tue, Nov 25, 2003 at 11:38:27AM +0100, Marek
> Kilimajer wrote:
> : Eugene Lee wrote:
> : >
> : >Try using more variables to make life a little
> easier to parse:
> : >
> : > $colname = $_FORM['form']
> : > $query = "select {$colname} from structure";
> : > $result = mysql_query($query);
> : > while (($row = mysql_fetch_array($result)) !==
> false)
> : > {
> : > echo $row[$colname];
> : > }
> : >
> :
> : Very dangerous. $colname can be anything, e.g.
> "mysql.user.password
> : colname FROM mysql.user #"
>
> I wrote it out this way because: the other user
> provided no source code,
> I wanted to show working code, it was late and I
> didn't feel like adding
> anything to secure against intrusions like SQL
> injection attacks. For
> the sake of completeness, redo the first line above
> as:
>
> $colname = mysql_escape_string($_FORM['form']);
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
Reply With Quote
  #7 (permalink)  
Old 11-26-2003
Marek Kilimajer
 
Posts: n/a
Default Re: [PHP] $ of variables, php, mysql

Eugene Lee wrote:
> On Tue, Nov 25, 2003 at 11:38:27AM +0100, Marek Kilimajer wrote:
> : Eugene Lee wrote:
> : >
> : >Try using more variables to make life a little easier to parse:
> : >
> : > $colname = $_FORM['form']
> : > $query = "select {$colname} from structure";
> : > $result = mysql_query($query);
> : > while (($row = mysql_fetch_array($result)) !== false)
> : > {
> : > echo $row[$colname];
> : > }
> : >
> :
> : Very dangerous. $colname can be anything, e.g. "mysql.user.password
> : colname FROM mysql.user #"
>
> I wrote it out this way because: the other user provided no source code,
> I wanted to show working code, it was late and I didn't feel like adding
> anything to secure against intrusions like SQL injection attacks. For
> the sake of completeness, redo the first line above as:
>
> $colname = mysql_escape_string($_FORM['form']);
>

That does not help at all, there is no character to be escaped in
"mysql.user.password colname FROM mysql.user #". The strig would have to
be in quotes, and column name cannot be in qoutes.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0