How To Use Yii::t() With Extensions

I have created an extension called GalleryManager, stored in the extensions directory of the application. I named this directory ‘gallerymanager’ and it has this structure:


gallerymanager

|--  assets

|--  messages

|    |-- en

|    |    |-- main.php

|    |-- es

|    |    |-- main.php

|    GalleryManager.php



My GalleryManager class (defined in GalleryManager.php) is like:

class GalleryManager extends CApplicationComponent{…

This is what the documentation says about defining Categories for translation:

So, I am trying a line like this in a view:


<?php echo Yii::t('GalleryManager.main', 'Add');?>

But this doesn’t work. What else do I have to do in order to make translations work for a Yii Extension?

Did you add your extension folder in your main config?

I have doubts with that, what should I add to ‘components’ section of config/main.php? the name of the class (GalleryManager) or the name of the main folder (gallerymanager)?

Maybe you should import it first in your import array


'import => array(

  ...

  'application.extensions.gallerymanager.*'

),

since you inheriting CApplicationComponent you can configure your component as any other component


main/config.php

...

'components'=>array(

    ...

        'gallery'=>array(

               'option1'=>''

        ),

    ...

)

... 



you can even configure your extension if you have any pre configuration you need done

The only way I could solve it was adding a line to the ‘extensionPaths’ in the ‘messages’ component like:


'messages' => array (

			'extensionPaths' => array(

				'gallerymanager' => 'ext.gallerymanager.messages',

			),

		),

Yii is lazy-loading. My guess is that where and when you run the echo Yii::t(‘GalleryManager.main’, ‘Add’) code your extension is not really loaded.