Closed tarampampam closed 8 years ago
I have php5.5 with native gettext working without problems in Ubuntu, so maybe there's a problem with your configuration. To be sure, can you try to use the php functions instead this library?
Native PHP gettext not working too. So, this is not your mistake, and here is my server configs:
What am I doing wrong?
Maybe you don't have the locale installed?
ps. I tested with this code:
$language = 'en';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
$domain = 'messages';
bindtextdomain($domain, "data/locales");
textdomain($domain);
echo gettext("Контакты");
Installed locale? What do you mean?
Native gettext use the locales installed in the operating system. This is why is so hard to use it under some circunstances. If you want to use, for instance the language "es", you have to install the locale in your operating system. Note also that the same locale is called differently in some operating systems (for example "es_ES" instead simply "es"). Here you can see how to configure it in ubuntu: http://stackoverflow.com/questions/5257519/cant-get-gettext-php-on-ubuntu-working I don't know how windows handle this.
I dont think what problem in installed locales. When i use php 5.4 or 5.3 - all work fine. Hm.. What the sh*t..
If you are using the native translator, you must have the locale installed and you must set the setLanguage
with fully system supported language:
sudo locale-gen en_US.UTF-8 de_DE.UTF-8
sudo update-locale
$translator = new \Gettext\GettextTranslator();
$translator->setLanguage('de_DE.UTF-8')->loadDomain(
'messages',
'data/locales'
);
die($translator->gettext('Контакты'));
Try!
Setting locale like 'de_DE.UTF-8' has no effect
My code working, from PHP 5.3 to PHP 7:
$locale = 'es_ES.UTF-8';
defined('LC_MESSAGES') or define('LC_MESSAGES', 5);
putenv('LANG='.$locale);
putenv('LANGUAGE='.$locale);
putenv('LC_MESSAGES='.$locale);
putenv('LC_PAPER='.$locale);
putenv('LC_TIME='.$locale);
putenv('LC_MONETARY='.$locale);
setlocale(LC_MESSAGES, $locale);
setlocale(LC_COLLATE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_MONETARY, $locale);
$translator = new GettextTranslator();
$translator->setLanguage($locale);
$translator->loadDomain('messages', 'gettext');
bind_textdomain_codeset('messages', 'UTF-8');
$translator->register();
But only works after install system package languages and reboot apache.
$locale = 'de';
defined('LC_MESSAGES') or define('LC_MESSAGES', 5);
putenv('LANG='.$locale);
putenv('LANGUAGE='.$locale);
putenv('LC_MESSAGES='.$locale);
putenv('LC_PAPER='.$locale);
putenv('LC_TIME='.$locale);
putenv('LC_MONETARY='.$locale);
setlocale(LC_MESSAGES, $locale);
setlocale(LC_COLLATE, $locale);
setlocale(LC_TIME, $locale);
setlocale(LC_MONETARY, $locale);
$translator = new \Gettext\GettextTranslator();
$translator->setLanguage($locale)->loadDomain(
'messages',
'data/locales'
);
die($translator->gettext('Контакты'));
Works with php 5.4, and does not works with php 5.5
IDK why.
And $locale = 'de_DE.UTF-8';
?
Yep, i tried. It has no effect too
Oops, here's the problem. I think there's nothing that this library can do.
Thx for support, guys. There is no way.
Hi guys.
I have one problem with your project and php ver.
5.5
. When i used5.3
or5.4
- all works fine, but when i updated php to5.5
- native translator (classGettextTranslator
,vendor\gettext\gettext\src\GettextTranslator.php
) stop working for me. If i use phpTranslator
(vendor\gettext\gettext\src\Translator.php
) - all is ok again, but i need exactly in native translator.Test string:
Files structure:
Test code:
First test:
Output:
All is ok. Second test:
Output:
My string is not translated. Test code was not changed.
Gettext installed by composer and source has no any changes by me:
Server software:
Can you fix this or say me how can i do it?