Jump to content

Translate String from Database


Recommended Posts

Hi, I'm developing a module and I'm trying to translate strings from database. This strings are administrables by a admin, in my module configuration page. The module must be compatible with prestashop 1.6, so I'm using the Classic module translation system (https://devdocs.prestashop.com/1.7/modules/creation/module-translation/classic-system/). 
The problem: I use variable to pass to l method, so it doesn't work:
 

// this won't work, the interpreter will ignore variables

$wording = 'Some wording'; $context = 'somecontext'; $this->l($wording, $context);

But the strings are in database, so I can't do it in other way, than variables.

I don't know how I must do that.

Any help will be appreciated. Thanks in advance

Link to comment
Share on other sites

Hi RobertoV, 

If you want to translate from database, you need to save these types of data to your database.

<?php
// fr.php

global $_MODULE;
$_MODULE = array();
$_MODULE['<{mymodule}prestashop>mymodule_2ddddc2a736e4128ce1cdfd22b041e7f'] = 'Mon module';
$_MODULE['<{mymodule}prestashop>mymodule_d6968577f69f08c93c209bd8b6b3d4d5'] = 'Description du module.';
$_MODULE['<{mymodule}prestashop>mymodule_533937acf0e84c92e787614bbb16a7a0'] = 'Êtes-vous certain de vouloir désinstaller ce module ? Vous perdrez tous vos réglages !';
$_MODULE['<{mymodule}prestashop>mymodule_0f40e8817b005044250943f57a21c5e7'] = 'Aucun nom fourni';

And then you need to create the fr.php file from the data you retrieve from the database. Check out the https://devdocs.prestashop.com/1.7/modules/creation/module-translation/classic-system/ link to understand more clearly. 

If I am not being clear, dont hesitate to knock knock again.

Link to comment
Share on other sites

I have seen the docs, but I dont know how to do it.

In the admin of the module the user can insert some words, which is showed in the product footer hook.

That word is stored in database. So as you explain, after he word is stored in database, I must open that file and insert new lines programatically? And then that new lines are enabled in the translator admin?

Thanks, and sorry for my englsih

Link to comment
Share on other sites

Hi,

You need to made the script by copy PrestaShop translation scan system. At first you need to scan module or theme's translation string, then you can store in database. 

After that you need to create the translation file automatically when you generate  the translation. This is the process you can do.

 

For PrestaShop they scan the file run time when you visit the page , then system generate the file. If you want to make sure they generate newly or added only new line. I suggest you to put some commented code block in the particular module translation php file then try to generated.

 

If your code remove, then you will understand , each time they overwrite the old file.

 

Hope you are clean now.

Thank you

  • Thanks 1
Link to comment
Share on other sites

The word "My module"'s  encrypted string is "2ddddc2a736e4128ce1cdfd22b041e7f". And translated version is "Mon module". You need to have these data on your database or json file or wherever you want to keep them. Then you need to generate a file like above. 

I hope that will do it.

Edited by ClassyDevs (see edit history)
  • Thanks 1
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...