Re: software localization with PHP

From: Date: Thu, 02 Aug 2001 17:42:16 +0000
Subject: Re: software localization with PHP
Groups: php.general 
Request: Send a blank email to php-general+get-60973@lists.php.net to get a copy of this message
I was just looking through the mailing list archives for some help with my gettext problem (basically, I can't get it to work). Anyway, I came across your post: > Thanks for the reply. This will not solve my problem. The problem is, for some > languages the sentence structure may be different. For example, the sentence > may need to be, > $greeting = "$first_name, welcome!" > as opposed to, > $greeting = "Welcome, $first_name!" This can be handled by gettext. Change your english code to something like: $greeting = sprintf( gettext("Welcome, %s!"), $first_name ); Once you run xgettext to extract all the strings, you'll end up with msgid "Welcome, %s!" msgstr "" So just convert it into whatever language, and move the "%s" as needed, eg: msgstr "%s, bonjour!" This even works with multiple "%s"'s, in later versions of PHP where you can rearrange the arguments in the format string, but not the way they are passed to sprintf(): msgid "%s is %d years old" msgstr "$2%d Jahrs habe $1%s" Check www.php.net/sprintf for details. Hope that helps. - Colin

« previous php.general (#60973) next »