ChDUP Posted July 13, 2016 Share Posted July 13, 2016 Hi In my module, I have an AdminController inside which I would like to write some texts and make its translatable. In Controller construct function, I've created an instance : $module_instance = new mymodule; Then, in Controller functions, I use this, for example : $module_instance->l('Delete selected'); I can retrieve "Delete selected" in Prestashop back-office / translations. But It never translates when I show my module controller. How must I do ? Thanks Link to comment Share on other sites More sharing options...
coeos.pro Posted July 13, 2016 Share Posted July 13, 2016 as tu essayé require_once('../mymodule.php'); $module_instance = new MyModule(); Link to comment Share on other sites More sharing options...
Krystian Podemski Posted July 13, 2016 Share Posted July 13, 2016 Hi, In controller it should be: $this->module->l('Translatable string'); on frontend: $this->module->l('Translatable string', 'controller_name'); Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 as tu essayé require_once('../mymodule.php'); $module_instance = new MyModule(); Oui, j'ai bien le require_once de mon module. Tu veux dire qu'il faut que je Capitalize le nom du module ? En réalité il s'appelle edelweiss_revenues. J'ai essayé $module_instance = Edelweiss_Revenues(); sans succès. Hi, In controller it should be: $this->module->l('Translatable string'); on frontend: $this->module->l('Translatable string', 'controller_name'); $this->module is the name of my module. In controller construct : $this->module = 'edelweiss_revenues'; of course, if I try $this->module->l('Translatable string'); I have an error Call to a member function l() on a non-object Link to comment Share on other sites More sharing options...
coeos.pro Posted July 13, 2016 Share Posted July 13, 2016 dans ton module tu as class MonModule extends Module il faut reprendre la casse MonModule et il faut éviter les _ dans les nom de modules, je ne sais pas si ça peut influer sur les traductions we must take the break MyModule and should be avoided _ in the name of modules, I do not know if it can affect translations Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 yes, in my module I have class edelweiss_revenues extends Module and in my controller : require_once _PS_MODULE_DIR_ . 'edelweiss_revenues/edelweiss_revenues.php'; class AdminRevenuesStatsController extends AdminController { public function __construct() { $this->revenues = new edelweiss_revenues; ... $this->revenues->l('text to translate'); -> it doesn't work. I will try to remove the underscore in my module name. Link to comment Share on other sites More sharing options...
Krystian Podemski Posted July 13, 2016 Share Posted July 13, 2016 You need to extend "ModuleAdminController" not "AdminController". Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 It's a module admin controller, not front. And what in $this->module ? Link to comment Share on other sites More sharing options...
Krystian Podemski Posted July 13, 2016 Share Posted July 13, 2016 Your module should base on ModuleAdminController.php and as you can see in this class you'll have access to $this->module We're writing about Back-Office, not Front-Office, you don't really need to use context while using translations in Back-Office Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 thanks everybody I extend now ModuleAdminController class AdminRevenuesStatsController extends ModuleAdminController And can now use $this->module without error. But still not translated. Link to comment Share on other sites More sharing options...
Krystian Podemski Posted July 13, 2016 Share Posted July 13, 2016 Check if everything is ok with your translation file, i don't know if it's fr.php, de.php or something, simply check if you have valid string there. It should work, unless you have some other issues with your code. Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 I've just try to totally delete the translation folder. And re-add my translation in Prestashop Back Office. Still doesn"t work ... I probably have another issue but don't see where. Link to comment Share on other sites More sharing options...
coeos.pro Posted July 13, 2016 Share Posted July 13, 2016 sinon essaye require_once('../mymodule.php'); $module_instance = new MyModule(); et dans mymodule.php, dans n'importe quelle fonction, rajoute la ligne $this->l('Delete selected'); et ensuite utilise la fonction de traduction des modules dans le back office pour traduire 'Delete selected' Link to comment Share on other sites More sharing options...
Krystian Podemski Posted July 13, 2016 Share Posted July 13, 2016 coeos.pro - please do not use French, here on English forum.And secondly, your solution is wrong. Totally wrong. Problem must be somewhere else. ChDUP - are you sure that you're have everything ok witihn your __construct method? parent::construct at the end of constructor in your class which extends ModuleAdminController? Also, just to make sure, you're trying to translate it in Localization -> Translations -> Installed modules -> Core (no theme), right? Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 Here is My admin Controller : <?php require_once _PS_MODULE_DIR_ . 'edelweiss_revenues/edelweiss_revenues.php'; class AdminRevenuesStatsController extends ModuleAdminController { public function __construct() { $this->name = 'revenues'; $this->lang = false; $this->context = Context::getContext(); $this->id_lang = (int)$this->context->language->id; $this->bootstrap = true; parent::__construct(); } public function postProcess() { echo($this->module->l('Text to translate')); die(); I've translated the 'Text to translate' in Localization -> Translations -> Installed modules -> Core and also in Localization -> Translations -> Installed modules -> MyTheme no success. Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 (edited) I've tried with and without ->module and with and without ,'controllername' no success in each case. Edited July 13, 2016 by ChDUP (see edit history) Link to comment Share on other sites More sharing options...
ChDUP Posted July 13, 2016 Author Share Posted July 13, 2016 ok just have echo($this->l('Text translate')); die(); in my postProcess function. no PHP cache extension and I see my translation changes in my module (in module / configuration) but still not in my controller. Link to comment Share on other sites More sharing options...
ChDUP Posted July 15, 2016 Author Share Posted July 15, 2016 No idea to help me please ? Link to comment Share on other sites More sharing options...
ChDUP Posted July 29, 2016 Author Share Posted July 29, 2016 UP need help please Link to comment Share on other sites More sharing options...
prestowicz Posted December 13, 2016 Share Posted December 13, 2016 (edited) UP need help please I don't know exactly what your code does look like, but in my case, I have an controller override where I need to obtain some translation labels from the global lang theme directory. I build and translate override function which behaves like the Translate.php getModuleTranslation() function. See my attached php Translate file. Usage: $txt = Translate::getControllerTranslation('product', 'full'); where 'product' is the translation view from the ProductController in PS BO translation page and 'full' is the desired translated label. Via this code you access the $_LANG gloabl variable (and not the $_MODULE like in previous examples) Edited December 13, 2016 by prestowicz (see edit history) Link to comment Share on other sites More sharing options...
ELEGANTAL Posted June 5, 2019 Share Posted June 5, 2019 (edited) Hello The solution I found to this problem was to use single quote inside l() function and add controller name to l() function like the following: $this->module->l('Your text.', 'Example') You should not pass controller class name, just use controller name. My controller class name is MymoduleExampleModuleFrontController but I have to use the key word Example because it is actual name of controller. Edited June 5, 2019 by ELEGANTAL (see edit history) Link to comment Share on other sites More sharing options...
Nishanthan93 Posted July 30, 2020 Share Posted July 30, 2020 On 7/13/2016 at 2:36 PM, Krystian Podemski said: Hi, In controller it should be: $this->module->l('Translatable string'); on frontend: $this->module->l('Translatable string', 'controller_name'); Thanks Its Works Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now