News:

Support the VirtueMart project and become a member

Main Menu

Custom fields required [solved] + multilanguage [need help]

Started by dieda2, July 21, 2016, 10:51:49 AM

Previous topic - Next topic

dieda2

Hi,

As many others I need the custom fields (text input type) to be required, hence I have successfully implemented the solution suggested here:

https://forum.virtuemart.net/index.php?topic=132908.0

My problem now is how to translate the alert message according to the selected frontend user! I have replaced the hardcoded message with JText::_('VMCUSTOM_ALERT') and I tried vmText::_('VMCUSTOM_ALERT').
I have managed to get the selected Language tag with a workaround, hence I can hard code a message according to that, but I would like to use .ini files instead and I can't find how! The plugin always picks up the default Language set in the backend only. What I tried so far (string is translated both inside the /vcustom/textinput/language dir - plg_vmcustom_textinput .ini files - and in the base language dir - com_virtuemart .ini files):

1) JPlugin::loadLanguage('com_virtuemart') -> this actually picks up the com_virtuemart .ini file, but
a) the loadLanguage method does not allow to define the Language tag.
b) whenever I try to set a path - as stated in the API description - the method stops working.

As a result the default site language is always picked up (it-IT).

2) $app=JFactory::getApplication('site')
$app->initialise();
$lang=JFactory::getLanguage();
$lang->load('plg_vmcustom_textinput', JPATH_SITE.'/plugins./vmcustom/textinput', $lg_tag);

No Language file is picked up and the placeholder string is shown.

3) $prop=array('autoloadLanguage' => true);
JPlugin::setProperties($prop);

Nothing happens.

Does anyone know how a string could be translated inside the Vmcustom Textinput plugin according to the site selected Language (and loading the corresponding .ini file) ?

Thanks

Elena

jjk

Quote from: dieda2 on July 21, 2016, 10:51:49 AM
My problem now is how to translate the alert message according to the selected frontend user!

Which alert message do you mean?
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

dieda2

Hi, I have modified the plugin so that textinput custom fileds are required, see the link I posted.
When a user submit the order and has not filled the required fields an alert message (hardcoded) pops up "Please fill the mandatory fields".
This is the string I want to translate, but I can't activate the MultiLanguage feature, in the sense I can't call the right .ini file from the plugin (right=the one coherent with the Language the user has selected in the front end).

So far I have solved with an if sentence

if ($lan=='en_GB') $msg= "Please..." ;
if ($an=='it_IT') $msg= "...";

but this means that for each Language added to the frontend one has to modify the plugin. I would prefer instead to do something like

$msg=vmText::_('MY_ALERT');

Elena

jjk

Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations