2
votes

I'm writing a website using ZendFramework and decided to use the gettext system to internationalize its content. In my views I write string in french and provide a this moment only one file "en.mo" to translate sentences to english. I would like to avoid to maintain a file "fr.mo" which would only translate a sentence to the exact same sentence.

Is there a way to tell Zend or gettext that when the locale is "fr" or "fr_FR" then there is no need to search for a translation file and the key string must be just returned as is ? Or maybe there is a reason to create the "identity translation" file fr.mo ?

Key-quotes of my code at this point :

Extract of my bootstrap:

 protected function _initTranslations() {
        $config = $this->getApplication()->getOptions();

        Zend_Locale::setDefault('en'); // fallback if detection fails completely

        $locale = new Zend_Locale();
        if ( !in_array($locale->getLanguage(), explode(',',$config['available_translations']))) {
            $locale->setLocale('en'); // requested language is not available => use english
        }

        $translate = new Zend_Translate(array(  'adapter' => 'gettext',
                                                'content' => APPLICATION_PATH.'/../languages/gda-'.$locale->getLanguage().'.mo',
                                                'locale' => $locale));


        $translate->setLocale($locale);

        $this->bootstrap('view');
        $this->getResource('view')->getHelper('translate')->setTranslator($translate);
    }

content of /languages/ :

gda-en.mo
gda-fr.mo  <== this one I would like to avoid maintaining

thanks

1

1 Answers

2
votes

Fluxine,

When using the gettext Adapter of Zend_Translate, you will need:

  • the gda.pot containing all your msg-id (in french in your case)
  • the gda-fr.po containing at least one translation in order to generate the gda-fr.mo (which will be almost empty ...)
  • some other translation files
    • gda-en.po to generate the gda-en.mo
    • gda-de.po to generate the gda-de.mo
    • ....
    • gda-XX.po to generate the gda-XX.mo

The important fact here is:

Your "identity translation", as you call it, needs to exist, otherwise Zend will complain about the fact that the "fr" (in your case) is not available

In poEdit, just translate one small to the same string, generate the corresponding *.mo file, save it, and forget about it.

You won't need to update your gda-fr.po file anymore, nor regenerating an updated gda-fr.po file.

The Adapter will return the original, french, string because there is no translation for it in the gda-fr.mo