mrborel
21-05-2010, 13:27
Salve a tutti,
dovrei utilizzare gettext. Seguendo varie guide sono riuscito a farmi uno script <?php
$domain="messages";
$lang = 'en_US.utf8';
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "/locale");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
putenv("LANGUAGE=$lang");
$dir=setlocale(LC_ALL, $lang);
echo 'setlocal:'.$dir."<br/>";
bindtextdomain("$domain", "./www/19");
$dir=textdomain("$domain");
echo gettext('Aide');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $lang; ?>" lang="<?php echo $lang; ?>">
<head><title><?php
echo _("Titolo");
?></title>
<meta http-equiv="Content- Type" content="text/html;charset=UTF-8"/>
</head><body><br/>
<a href="hello.php?lang=en">Inglese</a><? echo"<br />" ?>
<a href="hello.php?lang=it">Italiano</a> <? echo"<br />" ;?>
<a href="hello.php">torna</a> <? echo"<br />" ;
echo '<h2>'._('title').'</h2>';echo '<ul>'; echo '<li>'._('label one').'</li>';echo '<li>'._('label two').'</li>';echo '</ul>';?>
</body></html>
e il file messages.po che ne deriva con il comando xgettext a.php opportunamente modificato(almeno credo)
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-05-21 14:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: a.php:14
msgid "Aiuto!"
msgstr "Help"
#: a.php:18
msgid "Titolo"
msgstr "Title"
#: a.php:25
msgid "title"
msgstr "titolo"
#: a.php:25
msgid "label one"
msgstr "uno"
#: a.php:25
msgid "label two"
msgstr "due"
pero una volta compilato il file .po con msgfmt e creato il file .mo non mi funziona la traduzione, cioč non mi cambia niente dal file php iniziale. Grazie per l'aiuto.
dovrei utilizzare gettext. Seguendo varie guide sono riuscito a farmi uno script <?php
$domain="messages";
$lang = 'en_US.utf8';
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "/locale");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
putenv("LANGUAGE=$lang");
$dir=setlocale(LC_ALL, $lang);
echo 'setlocal:'.$dir."<br/>";
bindtextdomain("$domain", "./www/19");
$dir=textdomain("$domain");
echo gettext('Aide');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $lang; ?>" lang="<?php echo $lang; ?>">
<head><title><?php
echo _("Titolo");
?></title>
<meta http-equiv="Content- Type" content="text/html;charset=UTF-8"/>
</head><body><br/>
<a href="hello.php?lang=en">Inglese</a><? echo"<br />" ?>
<a href="hello.php?lang=it">Italiano</a> <? echo"<br />" ;?>
<a href="hello.php">torna</a> <? echo"<br />" ;
echo '<h2>'._('title').'</h2>';echo '<ul>'; echo '<li>'._('label one').'</li>';echo '<li>'._('label two').'</li>';echo '</ul>';?>
</body></html>
e il file messages.po che ne deriva con il comando xgettext a.php opportunamente modificato(almeno credo)
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-05-21 14:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: a.php:14
msgid "Aiuto!"
msgstr "Help"
#: a.php:18
msgid "Titolo"
msgstr "Title"
#: a.php:25
msgid "title"
msgstr "titolo"
#: a.php:25
msgid "label one"
msgstr "uno"
#: a.php:25
msgid "label two"
msgstr "due"
pero una volta compilato il file .po con msgfmt e creato il file .mo non mi funziona la traduzione, cioč non mi cambia niente dal file php iniziale. Grazie per l'aiuto.