Phalcon Gettext getLocale()返回false

时间:2019-03-31 15:14:16

标签: php phalcon gettext

我有3个翻译文件(hu,en,it),但是当我尝试将其翻译为“ it”时,getLocale()返回false。 “ hu”和“ en”效果很好。

我的getTranslation()功能很常见:

php
protected function getTranslation()
    {
        if (!function_exists('gettext')) {
            throw new \Phalcon\Exception('There\'s no gettext extension');
        }

        if (!\is_file(APP_PATH . '/locales/' . $this->selectedLanguageCode . '/LC_MESSAGES/messages.mo')) {
            throw new \Phalcon\Exception('There\'s no ' . APP_PATH . '/locales/' . $this->selectedLanguageCode . '/LC_MESSAGES/messages.mo' . ' file');
        }

        $translate = new \Phalcon\Translate\Adapter\Gettext([
            'category'      => LC_MESSAGES,
            'locale'        => $this->selectedLanguageCode . '.UTF8',
            'defaultDomain' => 'messages',
            'file'          => 'messages',
            'directory'     => APP_PATH . '/locales/',
        ]);

        return $translate;
    }

我写了一些行进行调试,然后返回:

php
print 'locale: ' . $this->selectedLanguageCode . '.UTF8' . '<br />';
var_dump($translate->getLocale());
die();

return $translate;

当我选择hu时,它说:

    locale: hu_HU.UTF8
    string(10) "hu_HU.UTF8"

当我选择“ en”时,它说:

    locale: en_US.UTF8
    string(10) "en_US.UTF8"

但是当我选择it时,它说:

locale: it_IT.UTF8
bool(false)

我试图用poEdit重新生成英语和意大利语的mo文件,但是问题是相同的。用英语工作,但用意大利语工作。

mo文件位于

/app/locales/en_US/LC_MESSAGES/messages.mo
/app/locales/it_IT/LC_MESSAGES/messages.mo

英语的mo文件为:

������������,������<�������P������Q���j��e����������������������������A T világa�Project-Id-Version: app 1.0
Report-Msgid-Bugs-To: notesz@xyz.xyz
POT-Creation-Date: 2019-03-31 15:19+0200
PO-Revision-Date: 2019-03-31 17:02+0200
Language-Team: 
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Generator: Poedit 2.2.1
Last-Translator: 
Plural-Forms: nplurals=2; plural=(n != 1);
Language: en_US
�T Group�

意大利语的mo文件为:

������������,������<�������P������Q���j��e����������������������������A T világa�Project-Id-Version: app 1.0
Report-Msgid-Bugs-To: notesz@xyz.xyz
POT-Creation-Date: 2019-03-31 15:19+0200
PO-Revision-Date: 2019-03-31 17:00+0200
Language-Team: 
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Generator: Poedit 2.2.1
Last-Translator: 
Plural-Forms: nplurals=2; plural=(n != 1);
Language: it_IT
�Il mondo di T

0 个答案:

没有答案