VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: gba on October 17, 2017, 11:32:03 am

Title: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 17, 2017, 11:32:03 am
Hi!

I am creating a VM plugin having a params field 'orderstatus':
Code: [Select]
<field name="plg_myplugin_orderstatus" type="sql"
description="PLG_MYPLUGIN_ORDERSTATUS_DESC"
label="PLG_MYPLUGIN_ORDERSTATUS_LABEL"
default=""
query="
SELECT `#__virtuemart_orderstates`.`virtuemart_orderstate_id`,`#__virtuemart_orderstates`.`order_status_name`
FROM  `#__virtuemart_orderstates`
WHERE `#__virtuemart_orderstates`.`published`=1
ORDER BY  `#__virtuemart_orderstates`.`ordering` ASC
"
key_field="virtuemart_orderstate_id"
value_field="order_status_name"
translate="translate"
/>

Although I am using the tag 'translate', VM language variables in #__virtuemart_orderstates.order_status_name are not translated, while other are translated (i. e. language overrides).
Is VM not fully compatible with Joomla's multilanguage features?

Kind regards,
Gerald
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: Milbo on October 17, 2017, 16:47:02 pm
the language file is not loaded
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 17, 2017, 17:07:40 pm
Code: [Select]
JFactory::getLanguage('com_virtuemart')
Right?

EDIT: No, I have no PHP file ... I have the XML file of the plugin. How do I load the language file there? ???
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: Studio 42 on October 17, 2017, 17:58:33 pm
You have to do your own field see https://docs.joomla.org/Creating_a_custom_form_field_type and load the language
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 17, 2017, 20:14:46 pm
Why cannot I use a standard Joomla field with an own created VM plugin?
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: Studio 42 on October 17, 2017, 20:17:32 pm
Because is not a standard field and Joomla do not load all language files.
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 17, 2017, 20:23:07 pm
Because is not a standard field and Joomla do not load all language files.

Actually it is a standard field:
https://docs.joomla.org/SQL_form_field_type (https://docs.joomla.org/SQL_form_field_type)

???
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: Studio 42 on October 17, 2017, 20:44:20 pm
You had a question, i give you the right answer.
Sorry if you don't understand, or not have the lust to write the code.
type="sql" is to use a query to load a list, it's not the role of this field to add any language files.
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 17, 2017, 20:55:49 pm
type="sql" is to use a query to load a list, it's not the role of this field to add any language files.

Ah, now I see ... thank you for the additional explanation!

Kind regards,
Gerald
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 24, 2017, 16:51:32 pm
Hi again!

If someone could help me:
In my plugin folder I created a subdir 'fields' containing a file 'sql.php':
Code: [Select]
<?php
defined
'_JEXEC' ) or die( 'Restricted access' );

JFormHelper::loadFieldClass('sql');

class 
MyFormFieldSql extends JFormFieldSql
{
protected function getOptions()
{
$options $this->getOptions();

if ($this->translate == true)
{
foreach ($options as $item
{
$item vmText::_($item);
}
}

return $options;
}
}
But I guess I have forgotten something ... nothing happens.
Function getOptions() is even not executed.

All I want is:
Run through the options of the sql field once again translating them with vmText::_().

Can anyone help me finding out, what is missing, please?
Thank you very much in advance!

Kind regards,
Gerald
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: Studio 42 on October 24, 2017, 23:14:05 pm
I answered you in the Joomla forum ;)
Title: Re: Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 25, 2017, 08:48:21 am
I answered you in the Joomla forum ;)
Thank you!

If anyone is interested:
https://forum.joomla.org/viewtopic.php?f=727&t=956096 (https://forum.joomla.org/viewtopic.php?f=727&t=956096)
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 25, 2017, 10:11:47 am
Just one more question here, because it is VM related and I cannot find any hint in the VM documentation:
What do I need to be able to use 'vmText' functions in my field class?
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: Milbo on October 25, 2017, 10:41:18 am
http://dev.virtuemart.net/projects/virtuemart/wiki/Developing_a_module_or_plugin_for_VirtueMart_2

"Use
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php');
to load the configuration object in your extension. Now you have loaded the main API of VirtueMart 2. To be sure that the vm config is loaded, you may use

$config = VmConfig::loadConfig();"

the loadConfig ensures also that the language is loaded
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 25, 2017, 11:13:40 am
Hi!

Thank you for your hint.

Unfortunately not working:
i. e. vmText::_("COM_VIRTUEMART_ORDER_STATUS_PENDING") returns COM_VIRTUEMART_ORDER_STATUS_PENDING.

Code: [Select]
protected function getOptions() {
if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php');
$config = VmConfig::loadConfig();

$options = parent::getOptions();

foreach ($options as $option) {
$option->text = vmText::_($option->text);
}

return $options;
}
Am I blind?  ???

Kind regards,
Gerald
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: Jörgen on October 25, 2017, 11:23:29 am
Hello

Should probably work anyway, but have You tried single quotes instead of double quotes ?

regards

Jörgen @ Kreativ Fotografi
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 25, 2017, 11:27:36 am
Hi!

No difference ...
Actually using vmText::_($option->text) no quotes are involved at all  ;)

Kind regards,
Gerald
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: Milbo on October 25, 2017, 11:34:11 am
no big deal, the order stati have their own language file. Just after loadConfig
Code: [Select]
vmLanguage::loadJLang('com_virtuemart_orders',TRUE);

When you change the language, then all already loaded language files get loaded automatically (can be suppressed with param)
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: gba on October 25, 2017, 11:38:32 am
Hi!

Thank you - translation works now!  :)

When you change the language, then all already loaded language files get loaded automatically (can be suppressed with param)
"already loaded language files get loaded automatically" - what do you mean with that?

Kind regards,
Gerald
Title: Re: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?
Post by: Milbo on October 25, 2017, 16:09:58 pm
When you change the language, you loaded for example 10 english language files. When you change to german, you would have to reload them. VM does this for you.