Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Core_Block_Abstract::__() use singleton for expr var #26

Closed
stalniy opened this issue Jun 10, 2012 · 1 comment
Closed

Mage_Core_Block_Abstract::__() use singleton for expr var #26

stalniy opened this issue Jun 10, 2012 · 1 comment

Comments

@stalniy
Copy link

stalniy commented Jun 10, 2012

    public function __()
    {
        $args = func_get_args();
        $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->getModuleName());
        array_unshift($args, $expr);
        return Mage::app()->getTranslator()->translate($args);
    }

You can use singleton $expr var, because if we look at the Mage_Core_Model_Tranlate::translate

public function translate() {
.............
        if ($text instanceof Mage_Core_Model_Translate_Expr) {
            $code = $text->getCode(self::SCOPE_SEPARATOR);
            $module = $text->getModule();
            $text = $text->getText();
            $translated = $this->_getTranslatedString($text, $code);
        }
.................
}

we will see that expr object is used only once to fetch args for Mage_Core_Model_Tranlate::_getTranslatedString(). You have a lot calls of __() method in templates, models, etc. It can improve perfomance.

And why do you use array_shift/array_unsfhit to get and pass first element of arguments array? Just use array index:

    public function __()
    {
        $args = func_get_args();
        if (!empty($args[0]) {
            $args[0] = new Mage_Core_Model_Translate_Expr($args[0], $this->getModuleName());
            return Mage::app()->getTranslator()->translate($args);
        }
    }
@magento-team
Copy link
Contributor

It is an valuable proposal. However, we have a broader story regarding refactoring of translation mechanism. Thus we won't do anything as proposed, because all this code is going to be deleted in scope of that story.

Out plan is to remove module context from translated text, and to use Gettext functionality directly.

Thank you for the proposal.

magento-team pushed a commit that referenced this issue Jan 16, 2015
[Folks] Technical debt (MAGETWO-26655)
This was referenced Mar 4, 2015
@stevieyu stevieyu mentioned this issue Apr 3, 2015
@FabXav FabXav mentioned this issue Oct 11, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants