views:

89

answers:

1

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

A: 

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

Julien
Thanks a lot, it makes senses to do what you suggest and it works as expected. Additionally I log missing translations into a file using Zend_Translate options, but since almost every translations are missing for french I'll get thousands of lines in my log file. Is there a known way of not logging missing translations for a particular locale ? Although logging missing translations is probably not the best way to handle the situation.
Fluxine
Logging the missing translation is kind of over engineered, as poEdit and the gettext format in general will help you keeping your translation template *.pot up to date (using the update form source, you will have XXX new, YYY obsolete). Then open each language file gda-*.po, and do an update from template, a.k.a. your gda.pot.
Julien
If you consider your question answered, click the green tick ;-)
Julien
Yes thanks, i suppose the green tick is voting your answer up but I need 15 reputation to do so, I hope someone will up for me until I can myself
Fluxine