Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Error include (NAMEModule.php) using Yii::t('NAMEModule.categoryName', 'message') without module init and import #1994

Closed
magefad opened this Issue Jan 16, 2013 · 12 comments

Comments

4 participants
Contributor

magefad commented Jan 16, 2013

Example Crisu83/yii-auth#15
I think in such constructions import module is redundant, because module not used in a Yii:t() function

Owner

cebe commented Jan 17, 2013

Why do you translate "Access denied" in Moduel context? You need to load the module to find the message files.
Check the guide on translation the part on message files for extension.

@cebe cebe closed this Jan 17, 2013

@cebe cebe was assigned Jan 17, 2013

Contributor

magefad commented Jan 17, 2013

Message is located in the filter (https://github.com/Crisu83/yii-auth/blob/master/components/AuthFilter.php) in module yii-auth, which in turn works with component "user" specified in main.php config.

The filter is specified in the controllers of other modules (http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#filter).

Just not logical way, for the sake of one filter with one call Yii::t() need to load a module and execute its init() (https://github.com/Crisu83/yii-auth/blob/master/AuthModule.php#L69) with many imports, no?

it's just a case of when it is not necessary to init() (getModule) module due to call Yi:t() not in module context

@cebe cebe reopened this Jan 17, 2013

Owner

cebe commented Jan 17, 2013

Okay, with #1958 we have two problems where initializing module is necessary but init() does too much. While init() might be needed by further usage of the module we can not simply skip it.
We have to define what kind of calls are allowed to do in init() and which are to be defined later in methods like beforeControllerAction(). maybe we need a step between that.

Owner

cebe commented Jan 17, 2013

I would mark this as a documentation and usage problem. Even Yii itself does it wrong in gii imo (see #1958).

Contributor

magefad commented Jan 17, 2013

Why not load the translation messages on the basis of the parameter 'category', but without the requirement that the module is loaded?

why we need to init the module in translation?

Member

mdomba commented Jan 17, 2013

But isn't this a wrong usage of Yii:t() in the filter ?

A filter in theory can be used with any module not with just one... so why use a module context in the call to t()?

Contributor

magefad commented Jan 17, 2013

I think that in addition to filters such problem can arise in other cases

Owner

cebe commented Jan 17, 2013

@mdomba I am not 100% sure what is wrong usage and what is wrong design. We need to rethink our design to see if it needs improvement or not. Had a Problem with module init before and solved it with a convention that worked in that project. not sure if it applies to the framework as well, will check that.

crisu83 commented Jan 19, 2013

Being the author of the module discussed here I cannot understand why the module itself needs to be loaded when Yii::t is called. It would be nice to be able provide translation for all strings within a single file that is bundled with the extension. What do you think?

Owner

cebe commented Jan 19, 2013

@crisu83 this is already possible (since 1.1.13). http://www.yiiframework.com/doc/api/1.1/CPhpMessageSource#extensionPaths-detail
When Module is used as category prefix, the module has to be loaded to get modules basePath to find message files.

Owner

cebe commented Apr 24, 2013

@crisu83 the module basePath is needed to load the translation files. Things like registering css and loading assets are better suited when put in beforeControllerAction()

@cebe cebe closed this Apr 24, 2013

Owner

cebe commented Apr 24, 2013

Can't see anything to improve here. As far as I see every situation can be solved with init() and beforeControllerAction()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment