2

After an update from Magento 1.7 to 1.9.1 .I get the following error:

Array ( 

[type] = 2 [message] = vsprintf(): Too few arguments [file]   /home/admin/domains/domainname.com/public_html/app/code/core/Mage/Core/Model/Translate.php [line] = 416 

)

On line 416 this line is visible: $result = @vsprintf($translated, $args);
Does anyone know how i can solve this?

Below the full code of the function

    /**
     * Translate
     *
     * @param   array $args
     * @return  string
     */

    public function translate($args)
    {
        $text = array_shift($args);

        if (is_string($text) && ''==$text
            || is_null($text)
            || is_bool($text) && false===$text
            || is_object($text) && ''==$text->getText()) {
            return '';
        }
        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);
        }
        else {
            if (!empty($_REQUEST['theme'])) {
                $module = 'frontend/default/'.$_REQUEST['theme'];
            } else {
                $module = 'frontend/default/default';
            }
            $code = $module.self::SCOPE_SEPARATOR.$text;
            $translated = $this->_getTranslatedString($text, $code);
        }

        //array_unshift($args, $translated);
        //$result = @call_user_func_array('sprintf', $args);

        $result = @vsprintf($translated, $args);
        if ($result === false) {
            $result = $translated;
        }

        if ($this->_translateInline && $this->getTranslateInline()) {
            if (strpos($result, '{{{')===false || strpos($result, '}}}')===false || strpos($result, '}}{{')===false) {
                $result = '{{{'.$result.'}}{{'.$translated.'}}{{'.$text.'}}{{'.$module.'}}}';
            }
        }

        return $result;
    }
2
  • I had edited my index.php file and was throwing this error. You might want to replace the file with fresh one. Commented Aug 14, 2015 at 1:43
  • Answer found, at least for my own situation. Commented Oct 5, 2015 at 8:41

1 Answer 1

3

I too experienced this problem and, at the same time, my products would not save in the admin. The reason was this: in order to diagnose another fault I had added a custom "register_shutdown_function()" call into my index.php (see below). I had left this in place after fixing the original issue. This causes the the errors that would normally be skipped/ignored (those with the @ at the front) to actually trigger : e.g.

@call_user_func_array('sprintf', $args);

This therefore was returning the actual error to the screen and also adding the same error output to response to any scripts called via ajax (such as the product save process) causing them to break.

Here is the register_shutdown_function I had left running which was causing the issue.

error_reporting(E_ALL | E_STRICT);
ini_set('error_reporting', E_ERROR);
/*register_shutdown_function("fatal_handler");
function fatal_handler() {
    $error = error_get_last();
    echo "<pre>";
    print_r($error);
    echo "</pre>";
}*/

Commenting this out, as shown, restored things to normality. I know the question is a bit old but this might help point someone in the right direction.

Basically, check you are not forcing ALL errors to show.

1
  • I for one left that fragment of code running that I had there to fix another error. I have still having some other issues, but this helped.
    – johnsnails
    Commented Mar 30, 2016 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.