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:
Messages for an extension class (e.g. a widget, a module) can be specially managed and used. In particular, if a message belongs to an extension whose class name is Xyz, then the message category can be specified in the format of ‘Xyz.categoryName’. And the corresponding message file is assumed to be ‘BasePath/messages/LanguageID/categoryName.php’, where ‘BasePath’ refers to the directory that contains the extension class file. When using Yii::t() to translate an extension message, the category name should be set as ‘Xyz.categoryName’.
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?
mateeyow
(Matthewt)
February 27, 2014, 2:27am
2
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)?
mateeyow
(Matthewt)
February 27, 2014, 2:37am
4
Maybe you should import it first in your import array
'import => array(
...
'application.extensions.gallerymanager.*'
),
alirz23
(Alirz23)
February 27, 2014, 4:21am
5
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',
),
),
boaz
(Boaz Rymland)
March 6, 2014, 8:24am
7
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.