使用Zend Translate和gettext文件的默认语言环境
After hours of battling with gettext
functions and admitting defeat, I downloaded the Zend Framework for use in my project. It finally worked with the gettext file that I have so far, but now I'm wondering how do I show the default text in the default locale?
Part of my config.php file (it's included in every file at the top):
<?php
// ...
define('LANGUAGE', (isset($_GET['lang']) && $_GET['lang'] === 'fr') ? 'fr-CA' : 'en-CA');
define('LOCALE', (isset($_GET['lang']) && $_GET['lang'] === 'fr') ? 'fr_CA' : 'en_CA');
// ...
$translator = new \Zend\I18n\Translator\Translator();
$translator->addTranslationFile('gettext', dirname(__FILE__) . '/locale/' . LOCALE . '.mo', 'messages', LOCALE);
$translator->setLocale(LOCALE);
The French translation works fine, but for English it is looking for the en_CA.mo
file (I'm assuming from the addTranslationFile()
method) which doesn't exist. How do I make it so that the keys are echoed if the English version is being displayed? It seems redundant to make an en_CA.mo file.
经过几个小时的 我的config.php文件的一部分( 它包含在顶部的每个文件中: p>
法语翻译工作正常,但对于英语,它正在寻找 gettext code>功能和承认失败后,我下载了Zend Framework 在我的项目中使用。 它最终使用了我到目前为止的gettext文件,但现在我想知道如何在默认语言环境中显示默认文本? p>
&lt;?php
// ...
define('LANGUAGE',(isset($ _ GET ['lang '])&amp;&amp; $ _GET ['lang'] ==='fr')?'fr-CA':'en-CA');
define('LOCALE',(isset($ _ GET ['lang '])&amp;&amp; $ _GET ['lang'] ==='fr')?'fr_CA':'en_CA');
// ...
$ translator = new \ Zend \ I18n \ Translator \ Translator();
$ translator-&gt; addTranslationFile('gettext',dirname(__ FILE__)。'/ locale /'。LOCALE。'。em','messages',LOCALE);
$ translator- &gt; setLocale(LOCALE);
code> pre>
en_CA.mo code>文件( 我假设不存在的
addTranslationFile() code>方法。 如何在显示英文版时回显键,如何制作? 制作en_CA.mo文件似乎是多余的。 p>
div>
If you are allowing multiple translations for different languages to be translated then you'll need to create at the very least a blank en_CA.mo file. Otherwise, you'll find errors being displayed. Since the en_CA.mo file is blank, the translation keys will be displayed instead of the actual translation itself.