Jump to content

Help with gettext and translations


Ignatius881

Recommended Posts

Hello.

 

Well, I need some help with this problem. I'll explain.

 

I'm helping a friend to develop a webpage, and we decided to internacionalize and localize it. I proposed gettext, I was working on it, and it works. But not as expected.

 

Here are two pieces of code and an image:

 

- /local.php:

 

<?php
$locale = "es_ES.utf8";
$I= $_SESSION["IDIOMA"];

if($I=="eo"){ $locale="eo.utf8"; }
if($I=="es"){ $locale="es_ES.utf8"; }
if($I=="en"){ $locale="en_GB.utf8"; }

if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", __DIR__."/locale");
textdomain("messages");
?>

 

- /es/login.php:

 

<?php require_once(__DIR__."/../local.php"); ?>

<?php
if($_GET["idiom"]=="es"){include("ES_es.php");}
if($_GET["idiom"]=="eo"){include("EO_eo.php");}
if($_GET["idiom"]=="vl"){include("ES_vl.php");}
if($_GET["idiom"]=="ek"){include("EU_ba.php");}

if(isset($SESSION)){
//header("location:user.php?mod=inicio"); /* Si ha iniciado la sesion, vamos a user.php */
//echo '<script>top.location.href="user.php?mod=inicio"</script>';
} else { 
/* Cerramos la parte de codigo PHP porque vamos a escribir bastante HTML y nos será mas cómodo así que metiendo echo's */
include("function_botones.php");
?>
<title><? print _("Identificación"); ?> </title>
<h1><? print _("Inicio de sesión"); ?>  </h1>
  <h2><? print _("Identificación"); ?> <?=$_GET["idiom"]?></h2>
<form action="comprueba.php" method="POST" class="miform" name="miform">
<? print _("Nombre:"); ?>  
  <input type="text" name="login"><br>
<? print _("Contraseña:"); ?> <input type="password" name="pass"><br>
<input type="hidden" name="IDIOMA"  value="<?=$_GET["idiom"]?>"/>
<br>
<!--<input type="submit" value="Entrar" class="boton">-->
<table width="100">
  <tr>
    <td><?=Boton(_("Entrar"),"azul","#","miform",false)?></td>
  </tr>
</table>
</form>
<?
} /* Y cerramos el else */ 
?>

 

All right, the comments, echos and prints are not important. The output of this code should return a translation of the texts (inicio de sesión > login, contraseña > password, etc.). But this happens:

 

19.png

 

So, /local.php is correct, /index.php (the text behind, originally in Spanish and localized as you can see) is correct, but /es/login.php seems to be wrong or something. I solved the problem about including a file which is in a higher level with __DIR__, but I don't understand.

 

Excuse me, I'm not an expert in php, but I want to learn more. So, what have I to do to see the window text translated? And excuse me if I don't explain well my problem.

 

I hope you can help me. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/244055-help-with-gettext-and-translations/
Share on other sites

you're using:

$_GET["idiom"]

but in the url the variable is called 'locale'

 

In fact, that wasn't the correct file :D

 

Ok, now the login window appears with the translation. But the rest of the page not. And there are many files involved, and I don't know what file is the correct. They are at least four files.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.