views:

19

answers:

1

Hey Guys,

I'm currently internationalizing an existing PHP project and thought the easiest way to do this is by just integrating I18n + gettext.

Currently I have a I18n.php:

<?php
setlocale(LC_ALL, 'de_DE.UTF-8');
bindtextdomain('cms', './locale');  
textdomain('cms');
?>

Which is being included in every file that needs some translation.

Example: login.inc.php:

include_once("i18n.php");
...
<tr>
                    <td width='40%' align='right'>"._('User Name').":</td>
                    <td width='60%'><input name='USERNAME' type='text' class='login_txt'></td>
                  </tr>
                  <tr>
                    <td align='right'>"._('Password').":</td>
                    <td><input name='PASSWORD' class='login_txt' type='password'></td>
                  </tr>
...

It kind works but I got one weird problem. It only translates the to things like 2 out of 10 times I load this page (2x "Benutzername", 8x "User Name"). Does anyone know what could cause this problem? I'm trying to figure it out for like an hour already and still no clue.

Since I'm writing here already: Does anyone know a better approach to internationalize an existing PHP projecT?

Thanks!

+1  A: 

Yes, there is a better way. See the ResourceBundle class and, in general, the intl extension.

Artefacto
Thanks, I'll have a look at that.
Cojones
It looks interesting but I couldn't find one single line of code of how to translate actual strings? Do you by any chance know a good tutorial or anything like that for the intl extension?
Cojones