开发者

PHP, I18n and gettext not working properly?

开发者 https://www.devze.com 2023-01-12 11:07 出处:网络
I\'m currently internationalizing an existing PHP project and thought the easiest way to do this is by just integrating I18n + gettext.

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 k开发者_Go百科ind 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!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消