Author Topic: [SOLVED] Why are VM language variables not translated in Joomla SQL field type?  (Read 2075 times)

gba

  • Jr. Member
  • **
  • Posts: 280
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

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9856
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #1 on: October 17, 2017, 16:47:02 pm »
the language file is not loaded
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #2 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? ???

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3960
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #3 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

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #4 on: October 17, 2017, 20:14:46 pm »
Why cannot I use a standard Joomla field with an own created VM plugin?

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3960
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #5 on: October 17, 2017, 20:17:32 pm »
Because is not a standard field and Joomla do not load all language files.

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #6 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

???

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3960
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #7 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.

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #8 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

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #9 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

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3960
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #10 on: October 24, 2017, 23:14:05 pm »
I answered you in the Joomla forum ;)

gba

  • Jr. Member
  • **
  • Posts: 280
Re: Why are VM language variables not translated in Joomla SQL field type?
« Reply #11 on: October 25, 2017, 08:48:21 am »

gba

  • Jr. Member
  • **
  • Posts: 280
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?

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9856
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
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
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

gba

  • Jr. Member
  • **
  • Posts: 280
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