Usando el paquete PHP-gettext

Volver.

Seleccione idioma para esta página

Castellano

Inglés

ninguno


Ella vestía una falda de color azul.

Este archivo


<?php
include 'php-gettext-1.0.7/streams.php';
include 
'php-gettext-1.0.7/gettext.php';

function 
__($texto) {
         global 
$gettext_tables;
         if (
is_null($gettext_tables)) return $texto;
         else return 
$gettext_tables->translate($texto);
}

session_start();
if (
$_GET['language']) $_SESSION['language'] = $_GET['language'];
if (!
array_key_exists('language',$_SESSION))$_SESSION['language'] = 'es';

if (
file_exists($_SESSION['language'] . '.mo')) {
   
$gettext_tables =   new gettext_reader( new CachedFileReader($_SESSION['language'] . '.mo'));
   if (!
is_null($gettext_tables)) $gettext_tables->load_tables();
}

?>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo __('Usando el paquete PHP-gettext'); ?></title>
</head><body>
<h1><?php echo __('Usando el paquete PHP-gettext'?></h1>
<p align="right"><a href="../"><?php echo __('Volver') , '.'?></a></p>
<p><?php echo __('Seleccione idioma para esta página'?></p>
<form method="get" action="index.php">
<p><input type="radio" name="language" value="es" <?php if ($_SESSION['language'] =='es') echo 'checked' ?> /> <?php echo __('Castellano'?></p>
<p><input type="radio" name="language" value="en" <?php if ($_SESSION['language'] =='en') echo 'checked' ?>/> <?php echo __('Inglés'?></p>
<p><input type="radio" name="language" value="xx" <?php if ($_SESSION['language'] =='xx') echo 'checked' ?>/> <?php echo __('ninguno'?></p>
<input type="submit" name="submit" value="<?php echo __('Aceptar'?>" />
</form>
<hr />
<?php printf(__('Ella vestía una %1$s de color %2$s.'),__('falda'),__('azul')); ?>
<hr />
<h3><?php echo __('Este archivo'?></h3>
<pre><?php highlight_file('index.php'); ?></pre>
<hr />
<h3><?php echo __('Archivo de traducciones'?></h3>
<pre><?php
$poFile 
$_SESSION['language'] . '.po';
if (
file_exists($poFile)) readfile($poFile) ; else echo __('no hay'); ?></pre>
</body></html>


Archivo de traducciones

no hay