Search code examples
prestashopprestashop-1.6

Prestashop 1.6 l method


There is an issue with the translations, if the translation is missing prestashop is returining empty string, rather than the key. Does anyone know the location of the 'l' method used in the controllers?

$this->l('string', 'mod'); //This will output '' if string is not translated.

I want to modify the method and make it return the key if the value is empty, but I cant find it.


Solution

  • I'll assume you are referring to an AdminController, since it's the only one using that function. It uses the function:

    protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
    {
        if ($class === null || $class == 'AdminTab') {
            $class = substr(get_class($this), 0, -10);
        } elseif (strtolower(substr($class, -10)) == 'controller') {
            /* classname has changed, from AdminXXX to AdminXXXController, so we remove 10 characters and we keep same keys */
            $class = substr($class, 0, -10);
        }
        return Translate::getAdminTranslation($string, $class, $addslashes, $htmlentities);
    }
    

    In your case it would call Translate::getAdminTranslation('string', 'mod', false, true)

    In Translate::getAdminTranslation We have:

    ...
    $string = preg_replace("/\\\*'/", "\'", $string);
    $key = md5($string);
    if (isset($_LANGADM[$class.$key])) {
        $str = $_LANGADM[$class.$key];
    } else {
        $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
    }
    ...
    

    Since it won't have the $_LANGADM[$class.$key], it will call:

    $str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
    

    in your case $str = Translate::getGenericAdminTranslation('string', md5('string'), $_LANGADM);

    In there we have:

    ...
    if (isset($lang_array['AdminController'.$key])) {
        $str = $lang_array['AdminController'.$key];
    } elseif (isset($lang_array['Helper'.$key])) {
        $str = $lang_array['Helper'.$key];
    } elseif (isset($lang_array['AdminTab'.$key])) {
        $str = $lang_array['AdminTab'.$key];
    } else {
        // note in 1.5, some translations has moved from AdminXX to helper/*.tpl
        $str = $string;
    }
    return $str;
    

    So by default if no key is found, the same string that is trying to be translated is returned. So there is no need to change the function.

    On the otherhand, make sure the string it's translated to an empty string. You can also debug these functions to make sure your class is correct, and the file that is storing the corresponding translations doesn't have the empty translation for those strings.