dsfdsf46465 2013-01-21 00:20
浏览 41
已采纳

使用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.

  • 写回答

1条回答 默认 最新

  • dtotuki47568 2013-01-21 21:39
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算