php-i18n Digest 5 Oct 2003 00:35:17 -0000 Issue 197
Topics (messages 618 through 622):
Re: iconv adds garbage while to UTF-8
618 by: Moriyoshi Koizumi
619 by: Peter Vereshagin
Re: gettext and variable parsing
620 by: Bjørn Tore Hagen
Configure flag for turning on/off the function alias "_()" for "gettext()"
621 by: Bjørn Tore Hagen
622 by: Moriyoshi Koizumi
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Just upgrade your php. 4.2.2 contains some buggy code.
Moriyoshi
Peter Vereshagin <[EMAIL PROTECTED]> wrote:
> Hello.
> I have php-4.2.2
> I have koi8-r encoded string and need to recode it to UTF-8.
> I use iconv() and see strange noise added to a string.
> I played with iconv_set_encoding()'s and setlocale(0 as well.
> Please suggest me a third-party encoding class.
> I always used the convert_cyr_string() but it doesn't seem to know UTF-8.
> my iconv system command does this job fine, but I need this in php.
--- End Message ---
--- Begin Message ---
Sorry it would be rather hard for me. I know I have security holes but I simply
built Recode extension. php-4.2.2 was the last built by Arvin where I use(d) to
download RPMS and - thanks! the comment near extension download helped from Apache
crash because of extension instability. I just put recode the first extension to be
used in my php.ini and at least got it.
Thu, Oct 02, 2003 at 08:08:08PM +0900 Moriyoshi Koizumi To Peter Vereshagin
MK> Just upgrade your php. 4.2.2 contains some buggy code.
MK>
MK> Moriyoshi
MK>
MK> Peter Vereshagin <[EMAIL PROTECTED]> wrote:
MK>
MK> > Hello.
MK> > I have php-4.2.2
MK> > I have koi8-r encoded string and need to recode it to UTF-8.
MK> > I use iconv() and see strange noise added to a string.
MK> > I played with iconv_set_encoding()'s and setlocale(0 as well.
MK> > Please suggest me a third-party encoding class.
MK> > I always used the convert_cyr_string() but it doesn't seem to know UTF-8.
MK> > my iconv system command does this job fine, but I need this in php.
--- End Message ---
--- Begin Message ---
On Mon, 11 Aug 2003 12:16:12 +0200, Christophe Chisogne
<[EMAIL PROTECTED]> wrote:
Ramil Sagum wrote:
echo _("Displaying records from $from to $to of $total");
Try with
printf( _("Displaying records from %d to %d of %d"),
$from, $to, $total );
It seems you must quote the strings with ".." for gettext to work.
For all "variable content" to be translated, you have to use
"format strings" (1st argument of printf, sprintf...).
By example, "%d" means to write the var as an integer.
With printf, sprintf etc gettext translate a static string
"Displaying records from %d to %d of %d"
It can translate it to, say,
"Affichage des enregistrements de %d à %d parmi %d".
Next, printf receive this format string, as if no i18n
has occured before.
One problem which might occur using printf/sprintf and gettext is that you
have several arguments to printf, and the translated string uses them i a
different order than specified in the code.
Example:
printf(_("There are %d monkeys in the tree, %d are red and %d are
green\n"), $monkeys, $red, $green);
Consider that translated into the following (both strings in english for
simplicity):
printf(_("%d green and %d red monkeys in a tree makes a total of %d
monkeys\n", $monkeys, $red, $green);
This will generate the wrong string.
In stead use:
printf(_("%3\$d green and %2\$d red monkeys in a tree makes a total of
%1\$d monkeys\n", $monkeys, $red, $green);
This will use the arguments in the correct order.
In .po format:
msgid "There are %d monkeys in the tree, %d are red and %d are green\n"
msgstr "%3\$d green and %2\$d red monkeys in a tree makes a total of %1\$d
monkeys\n"
Hope this will be usefull to someone!
--
mvh
Bjørn Tore Hagen
Programmer
--- End Message ---
--- Begin Message ---
Hello!
Not sure if this is right place for this, but anyways:
Wouldn't it be nice to have a configure flag for turning on/off the
function alias _() for the gettext() function, or maybe even a php.ini
setting if that's possible.
If this feature existed it would be possible to create your own _()
function which could do things in addition to calling gettext().
Example:
function _($string) {
$ret = gettext($string);
if ($ret == $string) {
/***
... notify of missing msgid in .mo/.po file ...
***/
}
return $ret;
}
This however would be slower than using the alias _() directly, but it
would be _VERY_ nice to have for debugging and development purposes.
--
Bjørn Tore Hagen
Programmer
--- End Message ---
--- Begin Message ---
Hi,
Perhaps it'd be better to write a feature request at http://bugs.php.net/ .
I like your idea, but could it be that simple by preparing a function like
__() and using it everywhere instead.
<?php // sample
if ($CONFIG['DEBUG_MODE']) {
function __($str) {
$retval = gettext($str);
if ($str == $retval) {
trigger_error("missing translation for "$str", E_USER_NOTICE);
}
return $retval;
}
} else {
function __($str) {
return gettext($str);
}
}
?>
Moriyoshi
>
> Not sure if this is right place for this, but anyways:
>
> Wouldn't it be nice to have a configure flag for turning on/off the
> function alias _() for the gettext() function, or maybe even a php.ini
> setting if that's possible.
>
> If this feature existed it would be possible to create your own _()
> function which could do things in addition to calling gettext().
>
> Example:
> function _($string) {
> $ret = gettext($string);
> if ($ret == $string) {
> /***
> ... notify of missing msgid in .mo/.po file ...
> ***/
> }
> return $ret;
> }
>
> This however would be slower than using the alias _() directly, but it
> would be _VERY_ nice to have for debugging and development purposes.
>
> --
> Bjørn Tore Hagen
> Programmer
>
> --
> PHP Internationalization Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---