Hi!
I am creating a VM plugin having a params field 'orderstatus':
<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
the language file is not loaded
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? ???
You have to do your own field see https://docs.joomla.org/Creating_a_custom_form_field_type and load the language
Why cannot I use a standard Joomla field with an own created VM plugin?
Because is not a standard field and Joomla do not load all language files.
Quote from: Studio 42 on October 17, 2017, 20:17:32 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)
???
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.
Quote from: Studio 42 on October 17, 2017, 20:44:20 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
Hi again!
If someone could help me:
In my plugin folder I created a subdir 'fields' containing a file 'sql.php':
<?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
I answered you in the Joomla forum ;)
Quote from: Studio 42 on October 24, 2017, 23:14:05 PM
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)
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?
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
Hi!
Thank you for your hint.
Unfortunately not working:
i. e. vmText::_("COM_VIRTUEMART_ORDER_STATUS_PENDING") returns COM_VIRTUEMART_ORDER_STATUS_PENDING.
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
Hello
Should probably work anyway, but have You tried single quotes instead of double quotes ?
regards
Jörgen @ Kreativ Fotografi
Hi!
No difference ...
Actually using vmText::_($option->text) no quotes are involved at all ;)
Kind regards,
Gerald
no big deal, the order stati have their own language file. Just after loadConfig
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)
Hi!
Thank you - translation works now! :)
Quote from: Milbo on October 25, 2017, 11:34:11 AM
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
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.