php-i18n Digest 21 Feb 2007 22:30:20 -0000 Issue 349
Topics (messages 1050 through 1052):
Re: what is the encoding of Zval IS_STRING for string literals when
unicode.semantics=off
1050 by: Norbert Lindenberg
1051 by: Andrei Zmievski
PHP Gettext:A quick tutorial (no attachments)
1052 by: Donn Ingle
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 ---
Hi Makoto,
The specification is pretty clear that unicode.semantics=off means
binary strings. But the specification leaves the possibility open
that, if you set unicode.script_encoding (or the encoding pragma) and
the unicode.runtime_encoding to different encodings, the PHP runtime
would convert the string literals from one encoding in your source
files to a different encoding in the runtime. The strings would still
be binary at runtime, but a different byte sequence than in the
source file. Such a behavior could be seen as compatible with PHP 5
because the default settings for unicode.script_encoding and
unicode.runtime_encoding are both UTF-8.
I would guess that the team hasn't thought of that interpretation,
that they really mean it when they say "if unicode.semantics is off,
PHP behaves as it did in the past," and that unicode.script_encoding
and the encoding pragma are totally ignored if unicode.semantics is
off. But it would be good to clarify this in the specification.
Regards,
Norbert
On Feb 8, 2007, at 16:14 , Makoto Tozawa wrote:
Hello,
When the unicode.semantics=off, in what encoding will the PHP 6
engine create Zval IS_STRING for the string literals?
I can think of two possibilities.
1. PHP 6 does the same as PHP 5 because unicode.semantics=off means
backwards compatibility. Thus they are binary data.
2. PHP 6 respects the unicode.script_encoding (or the encoding
pragma) and the unicode.runtime_encoding. Thus they are in
unicode.runtime_encoding.
Thank you,
Makoto
--
PHP Unicode & I18N Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
-------------------------------------
Norbert Lindenberg
Yahoo! Internationalization Architect
--- End Message ---
--- Begin Message ---
#1 is the behavior.
-Andrei
On Feb 8, 2007, at 4:14 PM, Makoto Tozawa wrote:
Hello,
When the unicode.semantics=off, in what encoding will the PHP 6
engine create Zval IS_STRING for the string literals?
I can think of two possibilities.
1. PHP 6 does the same as PHP 5 because unicode.semantics=off means
backwards compatibility. Thus they are binary data.
2. PHP 6 respects the unicode.script_encoding (or the encoding
pragma) and the unicode.runtime_encoding. Thus they are in
unicode.runtime_encoding.
Thank you,
Makoto
--
PHP Unicode & I18N Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
PHP version 4
Dev machine : Gnu/Linux Kubuntu Dapper
Hello, new here.
I was going to ask a question, but I did just a few more experiments and
suddenly I got this i18n thing working; so I thought I'd document my take
on the situation. The online stuff, like that O'Reilly tutorial, just plain
did not work for me. Go figure!
I am sure there are things I am missing, and others are just plain wrong;
all knowledge is welcome :)
My initial beef with Gettext:
=============================
Does gettext require the system (server) to have the locale you need (i.e.
many if not all of them) installed in some way? If so, and you have no
access to the server, how can you translate your pages for the Klingon
behind his browser?
It turns out that the server doesn't need any special locales, you can
make-up the names of the languages you want to support, this is how I did
it.
The PHP code
============
A simple page with a combo-box to choose a "language".
<?php
$text = "";
if ($_POST["from"] == "go") {
#If under bash I say : LANGUAGE=klingon
#AND I have: setlocale(LC_MESSAGES,'')
#THEN it translates properly
$lang = $_POST["lang"];
putenv("LANGUAGE=$lang"); //This works
#putenv("LANG=$lang"); // This DOES NOT WORK
//Just set it blank. If you put your lang into this func
//it will NOT work.
setlocale(LC_MESSAGES,'');
$domain = "appname"; //What you named your .po files
bindtextdomain($domain,"./locale"); //Where you put the locale dir.
textdomain($domain);
//So, mo's go ionto ./locale/$lang/LC_MESSAGES/appname.mo
$text = _("This is a test of gettext in PHP");
}
?>
<html><head><meta charset="utf-8"><title>langtest</title></head><body>
<FORM action="" method="POST" accept-charset="utf-8">
<SELECT name="lang">
<option>--choose--</option>
<option>english</option>
<option>af_ZA.UTF-8</option>
<option>xhosa</option>
<option>klingon</option>
</SELECT>
<INPUT type="submit" name="from" value="go">
</FORM>
<h1><?=$text?></h1>
</body></html>
Details & mysteries
===================
The thing that really puzzles me right now is that putenv statement. From
what the manual says it should NOT work when "safe mode" is off, which it
is on my apache and on my test server online. Still, gift-horses and
mouths ...
The important part is that putenv command. Use "LANGUAGE=" not "LANG=".
The next step is to use setlocale, but do not put your language into the
second parameter, if you do then things go mad. (I presume this is the part
where the server needs the locale installed, IF you use that 2nd param.)
Then I made a folder called "locale"
Under that I made three folders called:
"af_ZA.UTF-8" -- To be pedantic
"xhosa" -- Starting to experiment
"klingon" -- Gone right off the rails.
Within each a "LC_MESSAGES" folder.
Within those, the appropriate .mo files. (I won't expand, there are many
tuts online re gettext commands)
At the end I include the .po files.
Conclusion
==========
So, using this code I can have translation .po files for any number of
randomly named languages.
I will look into what the browser sends by way of locale information,
perhaps I can use a code from that, otherwise I can have my users choose a
language and dictate the codes as I like to.
hth
Donn.
I include only the translations, not the whole .po file.
appname.af.po
#: gettexttest.php:6
msgid "This is a test of gettext in PHP"
msgstr "Dit is 'n toets van gettext in PHP"
appname.xhosa.po
#: gettexttest.php:6
msgid "This is a test of gettext in PHP"
msgstr "ngaZama uGettext ipakathi iPHP"
appname.klingon.po
#: gettexttest.php:6
msgid "This is a test of gettext in PHP"
msgstr "Graaak mur zgrkk grrr aaaargh!"
--- End Message ---