views:

208

answers:

1

I need to just translate form error messages in my application.

The application is not multilingual, it is al in Slovak (so I already write labels and stuff in Slovak language), just need to translate error messages.

I have made this method in my bootstrap file:

protected function _initTranslate()
{
    $this->translate = new Zend_Translate('gettext',
                                          '/path/to/translation/source-sk.mo',
                                          'sk');
    Zend_Form::setDefaultTranslator($this->translate);
}

But how to create the source-sk.mo file? Do I need to download it somewhere from the Web?

+1  A: 

First you will need to download the PoEdit software and then you will need to configure it according to this post.

Once you have completed those steps, you will need to create a new catalog file from within PoEdit. In the creation dialog, click on the keywords tab, and then add function names that you wish to scan for in your code. With Zend Framework, this is typically just translate since you are probably using the translate() view helper. However you will want to also include setLabel so that it pulls your Zend_Form labels as well.

After you have created your catalog, you will need to scan your source code for translations. You do this by clicking Update from Sources under the Catalog menu. Once it has completed scanning your source code, it will display a list of all strings that need to be translated. You then go down the list and enter in the translation for each string. Now save the catalog to somewhere within your ZF application, preferably /languages, point your Zend_Translate declaration to this location and you are good to go.

If you adjust any labels or strings later on, you can always reopen the catalog with PoEdit, run Update from Sources again and it will pull all of the new changes for you to translate.

Mark
Labels are already written in SLovak, so they don't need to be translated, just the error messages. I don't use translate in my views because I need to translate just the error messages. So I should leave functions names empty? According to this post - http://weierophinney.net/matthew/archives/159-Zend_Form-Advanced-Features.html - Zend_Translate translates the error messages by default? And I will try this tomorrow and let you know if it works. I will come back here in case I would have some troubles (which I probably will have).
Richard Knop