FOF30\Form\Field\Components::translate PHP Method

translate() public method

Translate a list of objects with JText::_().
Since: 2.1
public translate ( stdClass $item, string $type ) : string
$item stdClass The component object
$type string The extension type (e.g. component)
return string $text The translated name of the extension
    public function translate($item, $type)
    {
        $platform = $this->form->getContainer()->platform;
        // Map the manifest cache to $item. This is needed to get the name from the
        // manifest_cache and NOT from the name column, else some JText::_() translations fails.
        $mData = json_decode($item->manifest_cache);
        if ($mData) {
            foreach ($mData as $key => $value) {
                if ($key == 'type') {
                    // Ignore the type field
                    continue;
                }
                $item->{$key} = $value;
            }
        }
        $lang = $platform->getLanguage();
        switch ($type) {
            case 'component':
                $source = JPATH_ADMINISTRATOR . '/components/' . $item->element;
                $lang->load("{$item->element}.sys", JPATH_ADMINISTRATOR, null, false, false) || $lang->load("{$item->element}.sys", $source, null, false, false) || $lang->load("{$item->element}.sys", JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load("{$item->element}.sys", $source, $lang->getDefault(), false, false);
                break;
        }
        $text = JText::_($item->name);
        return $text;
    }