Juhas0 Posted January 24, 2017 Share Posted January 24, 2017 Hi, I am creating my first module. I want it to be multilingual. Some presta modules on their configuration page give possibility to enter text for different languages (they have for example some kind of button to choose current language near textfield). So I tried to do that, but I didn't manage. I know how to create simple form using HelperForm. But I don't have any idea how to add to this form multi language functionality. Can anybody help? Link to comment Share on other sites More sharing options...
presta4you.com Posted January 25, 2017 Share Posted January 25, 2017 For add multialnguage text you must change your every content from format 'text' to $this->l('text', 'module_name). After that you'll be able to translate your text on back-office. Link to comment Share on other sites More sharing options...
Knowband Plugins Posted January 26, 2017 Share Posted January 26, 2017 You can use the following code to add a multi-language field in the HelperForm class: array( 'type' => 'textarea', 'label' => $this->l('Enter small note'), 'name' => 'age_verification_note', 'hint' => $this->l('Enter the small note to be display at the top'), 'desc' => $this->l('Only 120 character allowed.'), 'class' => 'optn_general', 'lang' => true, 'required' => true, 'maxlength' => 120, 'cols' => 100, ) Check following URL for reference: http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class Link to comment Share on other sites More sharing options...
Juhas0 Posted January 26, 2017 Author Share Posted January 26, 2017 Hmm, I hoped it would be that simple Check following URL for reference: http://doc.prestashop.com/display/PS16/Using+the+HelperForm+class I hoped it would be that simple. But it isn't. When I add this attribute: 'lang' => true, my textarea becomes invisible. This is my input definition for this field: array( 'type' => 'textarea', 'class' => 'rte autoload_rte rte', 'label' => $this->l('Description'), 'name' => 'html', 'lang' => true, 'required' => true ), Link to comment Share on other sites More sharing options...
Juhas0 Posted January 30, 2017 Author Share Posted January 30, 2017 (edited) OK, so I noticed that giving 'lang' attribute is not enought. I found out that I have to do some other things: - get available languages, set default language and add them to HelperForm: //this is not optimal, but it shows how to do this $languages = Language::getLanguages(false); foreach ($languages as $k => $language) $languages[$k]['is_default'] = (int)$language['id_lang'] == Configuration::get('PS_LANG_DEFAULT'); $helper->languages = $languages; But still there is something wrong. When I open this page I get warnings: Notice line 775 in file www\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code[8] Uninitialized string offset: 1Notice line 775 in file www\prestashop\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code[8] Uninitialized string offset: 2 And I just can't figure it out. Could anyone help? Please, it's killing me. [EDIT] Eureka! At last! Field that is to be multilingual must be filled with content for every language. And this field is an array of strings with keys representing language id. So one should do something like that: foreach ($helper->languages as $language) { $helper->fields_value['html'][$language['id_lang']] = ""; } Of course this is bad example, because 'html' field will always have empty string. But I didn't figure it out yet, how to get proper values from existing object. Edited January 30, 2017 by Juhas0 (see edit history) 1 Link to comment Share on other sites More sharing options...
Marxio Posted April 27, 2021 Share Posted April 27, 2021 (edited) I need an example of multilingual module. Thanks. Edited April 27, 2021 by Marxio (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted April 28, 2021 Share Posted April 28, 2021 12 hours ago, Marxio said: I need an example of multilingual module. Thanks Check some of the standard modules e.g. ps_customtext 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