|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-08-24 16:49 UTC] raulsalitrero at gmail dot com
Description:
------------
usign gettext functions under php 5.3.0 (built with vc9) works differently to how it used to work in php 5.2.x (tested on 5.2.10 built with vc6).
it used to work even after a setlocale error, (locale not supported on my machine), after the error it continued loading the .mo (.po) files from the locale folder in the app. in php 5.3 it doesn't seem to load the files, i've tried changing the locale to the correct name for windows wich is "enu" and the path to the correct locale folder to:
locale/
enu/...
en_us/...
en_US/...
English_United States/...
English_United States.1252/... (changing the setlocale codeset from "UTF-8" to "CP1252" and "1252", and various combinations of the above settings, also with and without the codeset functions, and it didn't show translations.
in php 5.2.10 it loaded the files directly from the first settings
id like to know if it is possible to make php_gettext to ignore the setlocal error and work out the folder name from the LANG and LC_ALL enviroment variables like it apparently used to be in earlier versions of php. or if it would be too much troublesome, then if it could be possible to add a new function that returns the folder name where the the .mo files are being expected to be, something like:
gettext_getpath([$text_domain = Current_default_domain])
and get something like "en_US\LC_MESSAGES\domain.mo" (locale folder name) or the full path something like "C:\Apache\htdocs\app\locale\en_US\LC_MESSAGES\domain.mo" or "/var/www/app1/locale/en_US/LC_MESSAGES/domain.mo" in *nix (even if the file doesn't exists to know if its necessary to rename/move folders
thanks in advance
Reproduce code:
---------------
<?php
$locale = "en";
@error_reporting(E_ALL - E_NOTICE);
$mensaje="";
if (isSet($_GET["locale"])){
$locale = $_GET["locale"];
}
setlocale(LC_ALL, $locale);
if(false == putenv("LC_ALL=$locale")){echo "error lc_all";}
if(false == putenv("LANG=$locale")){echo "error lang";}
if(false == putenv("LANGUAGE=$locale")){echo "error language";}
textdomain("messages");
bindtextdomain("messages", "locale");
bind_textdomain_codeset("messages","UTF-8");
textdomain("messages");
echo _("hola mundo");
Expected result:
----------------
(having messages.po and messages.mo files with the translation "hola mundo" -> "hello world" (english)
in the relative path "locale/en/LC_MESSAGES/"
"hello world"
Actual result:
--------------
"hola mundo" (text not being translated)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
On windows vista sp2 + php-5.3.0-Win32-VC9-x86 gettext function always searches for "en_US" or "en" path in locale directory. PHP 5.2.3 is okay. this code produces different results <? putenv("LC_ALL=ru"); echo setlocale(LC_ALL,"ru"); bindtextdomain("messages", "./locale"); bind_textdomain_codeset("messages", "utf8"); textdomain("messages"); echo _("Application");exit; ?> In php 5.3.0 it does not translate.I have got this problem as well. I'd like to add that the system default language/locale gets translated. But no other languages. Example: I have windows vista, English version, and the system default locale is set to Swedish. The strings that are supposed to be translated are all written in English; _("Hello World!"). I have made three translations: ./se/LC_MESSAGES/default.mo ./de/LC_MESSAGES/default.mo ./en/LC_MESSAGES/default.mo /*nonsense words/phrases only for testing*/ I always get the Swedish translation no matter what configurations* I try. If I rename the Swedish translation file I get no translation at all, only the default string. * I've tried all kind of parameters for the following: setlocale(LC_ALL, ...); putenv("LANGUAGE=..."); putenv("LANG=...");putenv("LC_ALL=...");Windows Server 2008 R2 x64 with IIS 7.5 PHP 5.3.0, 5.3.2 Locale is English (Australian). Trying to get English (United States) to work. have ./locale/en_AU/LC_MESSAGES/messages.mo ./locale/en_US/LC_MESSAGES/messages.mo Always get the default (Australian) You stated: "The work around is explained in this report." So, but this escapes me. Where is the workaround? I have read this thread several times. Question: why does _SERVER["HTTP_ACCEPT_LANGUAGE"] have en-AU and not en_AU??? Or is this just a silly Winblows thing.