Question

I created a new module using MVC.

In my ObjectModel Class, I overload displayFieldName() function in order to get human reading fields errors when users doesn't fill a form well.

For example: "The Start date field is required" instead of "The start_date field is required".

I can't found how to translate this field within this function

/* Overload */
public static function displayFieldName($field, $class = __CLASS__, $htmlentities = true, Context $context = null)
{
    $fieldname = array(
        'date_start' => 'Start date',
        'title' => 'Title',
    );
    if ($fieldname[$field])
        return $fieldname[$field];
    else
        return $field;
}

I tried many things but can't find the usual l() function from here. Any idea?

Was it helpful?

Solution

You don't need to do that at all. It is already implemented in PrestaShop.

BackOffice > Localization > Translation > Field name translations

Note that during the installation you must copy your object model file in classes folder.

So if you have Object Model called MyDataObject you must have:

classes/MyDataObject.php in which you must have

<?php

class MyDataObjectCore extends ObjectModel
{

}

Do not forget the "Core" suffix, because the Fields Translation functionality needs it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top