Jump to content

Recommended Posts

Hello everyone,

 

How can I translate a module by editing the <lang>.php file (for example fr.php for French) in Prestashop 1.6.1.4?

 

I have already read the prestashop article about the translations and it says explicitly that we must not edit these files and use the administration panel instead.

 

However I can not use it, because I am getting the max_input_vars warning message, which says that I must increase the value of max_input_vars. I am using a shared hosting server and my hosting provider does not allow me to change the value, becaue this would affect all users on the same server, so I do not have permissions to edit httpd.conf or php.ini.

 

I have also tried to edit the .htaccess file in the root folder of my store and I have added the following line:

 

<IfModule mod_php5.c>
    ...
    php_value max_input_vars 2200
    ...
</IfModule>
 
but this still did not change the max_input_vars value. I also had a look in the admin folder to see if there is another .htaccess file, which might override the one I've edited, but there isn't.
 
How can I translate the module then?
 
Thanks in advance

 

 

Link to comment
Share on other sites

Contact your provider. He should adapt the value in your host. If own PHP.INI is not applying, than you dont have rights for to adapt server settings by your own.

Thanks for the quick response.

 

As I have already mentioned, I have contacted the hosting provider, but he explained to me that he can not change the value of max_input_vars, because this change would affect other users too and that is why I am looking for an alternative solution.

Link to comment
Share on other sites

The problem is that each string has a hash code that must be exactly right for it to work. Luckily, the hash code is the same whether the file is in the module's directory or your theme's directory. It's just the prefix before the hash code that needs to be changed slightly. Hopefully, you can find a language file somewhere that contains the hash codes, then you can copy the file and replace all the strings after the = sign with your translations.

 

For example, here is the translation for 'Top-sellers block' in modules/blockbestsellers/translations/en.php:

$_MODULE['<{blockbestsellers}prestashop>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Top-sellers block';

Here's the same line in modules/blockbestsellers/translations/fr.php:

$_MODULE['<{blockbestsellers}prestashop>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Bloc meilleures ventes';

You'll notice the the only different is the translation itself, so if you have one translation file with all the hashes, you copy it to create translations for other languages. All you need is the right ISO code followed by .php. Note however, that there is another difference when adding a translation inside a theme. Here's the same line in themes/default-bootstrap/modules/blockbestsellers/translations/fr.php:

$_MODULE['<{blockbestsellers}default-bootstrap>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Bloc meilleures ventes';

Notice that prestashop has changed to the name of the theme, so make sure to change every line when adding theme translations.

  • Like 2
Link to comment
Share on other sites

The problem is that each string has a hash code that must be exactly right for it to work. Luckily, the hash code is the same whether the file is in the module's directory or your theme's directory. It's just the prefix before the hash code that needs to be changed slightly. Hopefully, you can find a language file somewhere that contains the hash codes, then you can copy the file and replace all the strings after the = sign with your translations.

 

For example, here is the translation for 'Top-sellers block' in modules/blockbestsellers/translations/en.php:

$_MODULE['<{blockbestsellers}prestashop>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Top-sellers block';

Here's the same line in modules/blockbestsellers/translations/fr.php:

$_MODULE['<{blockbestsellers}prestashop>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Bloc meilleures ventes';

You'll notice the the only different is the translation itself, so if you have one translation file with all the hashes, you copy it to create translations for other languages. All you need is the right ISO code followed by .php. Note however, that there is another difference when adding a translation inside a theme. Here's the same line in themes/default-bootstrap/modules/blockbestsellers/translations/fr.php:

$_MODULE['<{blockbestsellers}default-bootstrap>blockbestsellers_9862f1949f776f69155b6e6b330c7ee1'] = 'Bloc meilleures ventes';

Notice that prestashop has changed to the name of the theme, so make sure to change every line when adding theme translations.

Thanks very much!

 

This is exactly the answer I've needed.

 

I was trying to translate cashondelivery module and I've found some useful cashondelivery.zip files which were containing some of the hashes that I've needed. However there is probably a later version and 3 of the phrases can not be translated with those hashes.

 

Can anyone please send me their translations of the cashondelivery module, so that I can find the hashes needed. My version of the module is 0.7.5.

Link to comment
Share on other sites

I just realised you can generate the hash code yourself using an online MD5 generator like the one here. Just enter the English string from the TPL file. For example, enter the string Pay with cash on delivery (COD) to get the hash code b7ada96a0da7ee7fb5371cca0b036d5c.

  • Like 2
Link to comment
Share on other sites

I just realised you can generate the hash code yourself using an online MD5 generator like the one here. Just enter the English string from the TPL file. For example, enter the string Pay with cash on delivery (COD) to get the hash code b7ada96a0da7ee7fb5371cca0b036d5c.

Thanks once again!

 

I've generated MD5 and now everything works perfectly.

Link to comment
Share on other sites

  • 3 months later...

Hello friends

 

I have problems with my PS 1.6.1.6 installation, which shows "Controller not found" error when the translations page in back office is accessed. I am working with a prestashop site which was configured by someone else and customer wants me to add a new module there.

 

Due to this language controller error, I was trying to find a workaround to implement translations for my module and rocky's suggestion worked perfectly for me.  Thank you so much Rocky.

 

But I have another problem with translations, which I could not figure out how to solve.  Before putting my problem, let me tell you that I am very much a beginner in Prestashop and this is the first module in my life that I am creating on Prestashop :(.

 

In my module file ('mymodule.php'), I am adding a template as a hook to show in order details page.  This is my install method in 'mymodule.php'

public function install() {
    if(Shop::isFeatureActive())
        Shop::setContext(Shop::CONTEXT_ALL);

    if(!parent::install() || !$this->registerHook('displayOrderDetail'))
        return false;

    return true;
}

And here is the hooking function (not sure if this is the right terminology)

public function hookDisplayOrderDetail($params) {
    return $this->display(__FILE__, 'myordertrack.tpl');
}

All translations are working on module.php (as I can see the translated strings in back office for module description and on config page).  But inside 'myordertrack.tpl', I don't see translated strings showing on order details page. For example: 

<h1 class="page-heading">{l s='Order Tracking' mod='mymodule'}</h1>

This shows 'Order Tracking' itself as the heading on order details page.  But I have added translations for this too as I did for module page translations.  This is the translation string I used in 'en.php' under 'mymodule' folder

$_MODULE['<{mymodule}prestashop>mymodule_f6a566b2cb5358a6d47d58e4d13df905'] = 'Order Shipment Status';
Can anyone please guide me to solve this?
 
Thanks & Regards
Sujith
Link to comment
Share on other sites

Thanks for your quick response

 

In fact, this is a new module which I am developing and there is no folder like "mymodule" inside themes/<my_theme>/modules/.  So I may have to create one there and add translation strings for my module, right?

 

Let me try that way.

 

Thanks & Regards

Sujith

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...