1

I am trying to create a component. I have the following manifest file:

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.4" method="upgrade">

    <name>COM_EXAMPLE_TITLE</name>
    <libraryname>example</libraryname>
    <creationDate>January 2017</creationDate>
    <author>inf3rno</author>
    <authorEmail>laszlo.janszky@gmail.com</authorEmail>
    <license>MIT</license>
    <version>0.0.1</version>
    <description>COM_EXAMPLE_DESCRIPTION</description>

    <scriptfile>installer.php</scriptfile>

    <files>
        <filename>example.php</filename>
        <folder>views</folder>
        <folder>src</folder>
        <folder>language</folder>
        <folder>media</folder>
    </files>

    <administration>
        <menu link="option=com_example">COM_EXAMPLE_TITLE</menu>
        <files>
            <filename>example.php</filename>
            <folder>src</folder>
            <folder>language</folder>
            <folder>media</folder>
        </files>
    </administration>

</extension>

In the language folder I have 4 ini files:

  • en-GB.com_example.ini
  • en-GB.com_example.sys.ini
  • hu-HU.com_example.ini
  • hu-HU.com_example.sys.ini

and I have the constants COM_EXAMPLE_TITLE and COM_EXAMPLE_DESCRIPTION in these files. I don't want to use the MVC classes Joomla provides and I want to reuse the src folder, which contains my classes.

The main problem that Joomla does not replace the constant names with the values, so when I install this component the registered component will be COM_EXAMPLE_TITLE instead of example and the name it displays in the admin menu will be com-example-title instead of e.g. Example Component or whatever I store in the COM_EXAMPLE_TITLE constant.

I don't understand why it does not work. I tried out with the <languages> element too and with en-GB and hu-HU subfolders too. Nothing worked, no matter what I changed. I installed Joomla 3.4.3 on localhost, but I have the same version on the production server. On the production server with the <languages> element I managed to make this work. Is there a configuration option or whatever which turned off the inclusion of these constants? Can this feature be turned off, or something else is going on here?

edit:

I checked my old more or less working code. Is there a chance it never worked properly? I have these multilingual texts in the admin menu and in the site menu, but by install I cannot have for example multilingual extension name and description. Now that is interesting, since this example tells me it is possible. Maybe by the later versions only, I don't know.

I tested further, with the <folder>language</folder> it works too if the files are in the ln-LN subfolders, but the package name and description does not work, just the admin menu. The same is on the production server, so this is not a config option, it simply is not supported. Probably the version is too old.

2

The language constants aren't being translated because you haven't defined your languages in the XML file.

You can do that like so:

<files>
    <folder>language</folder>    <<< You don't need this
</files>

// Site languages
<languages folder="site/language">
    <language tag="en-GB">en-GB/en-GB.com_example.ini</language>
    <language tag="en-GB">en-GB/en-GB.com_example.sys.ini</language>
    <language tag="hu-HU">hu-HU/hu-HU.com_example.ini</language>
    <language tag="hu-HU">hu-HU/hu-HU.com_example.sys.ini</language>
</languages>

// Admin languages
<administration>
    <languages folder="admin/language">
        <language tag="en-GB">en-GB/en-GB.com_example.ini</language>
        <language tag="en-GB">en-GB/en-GB.com_example.sys.ini</language>
        <language tag="hu-HU">hu-HU/hu-HU.com_example.ini</language>
        <language tag="hu-HU">hu-HU/hu-HU.com_example.sys.ini</language>
    </languages>
</administration>

Hope this helps

  • I tried out every possible combination including this. It did not work. I'll try it again if you say so. Maybe. In theory I only have to give the sys.ini to the admin part, because that is use by installing the component. – inf3rno Feb 7 '17 at 13:19
  • Yepp, it does not work. Does 3.4.3 support this feature? – inf3rno Feb 7 '17 at 13:27
  • Yes, it's the same for all Joomla versions, though I have no idea why you're on 3.4.3, which has poses security risks – Lodder Feb 7 '17 at 13:53
  • I don't want to be the site maintainer, I just want to end this project and forget it... I am not sure why it does not work then, I'll check later the code of the manifest xml processor, maybe that answers the question. – inf3rno Feb 7 '17 at 23:23
  • and have you defined the language constant in the .sys.ini file? – Lodder Feb 7 '17 at 23:28
2

I found the relevant part of code in an example joomla project.

public function loadLanguage($path = null)
{
    $source = $this->parent->getPath('source');
    if (!$source)
    {
        $this->parent->setPath('source', JPATH_PLATFORM . '/' . $this->parent->extension->element);
    }
    $this->manifest = $this->parent->getManifest();
    $extension = 'lib_' . strtolower(JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'));
    $name = strtolower((string) $this->manifest->libraryname);
    $lang = JFactory::getLanguage();
    $source = $path ? $path : JPATH_PLATFORM . "/$name";
    $lang->load($extension . '.sys', $source, null, false, false)
        || $lang->load($extension . '.sys', JPATH_SITE, null, false, false)
        || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false)
        || $lang->load($extension . '.sys', JPATH_SITE, $lang->getDefault(), false, false);
}

But it is present in the current joomla version as well.

public function loadLanguage($path = null)
{
    $source = $this->parent->getPath('source');
    if (!$source)
    {
        $this->parent->setPath('source', JPATH_PLATFORM . '/' . $this->getElement());
    }
    $extension = 'lib_' . $this->getElement();
    $librarypath = (string) $this->getManifest()->libraryname;
    $source = $path ?: JPATH_PLATFORM . '/' . $librarypath;
    $this->doLoadLanguage($extension, $source, JPATH_SITE);
}

I think the first code is easier to understand.

$extension = 'lib_' . strtolower(JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'));
$name = strtolower((string) $this->manifest->libraryname);
$lang = JFactory::getLanguage();
$source = $path ? $path : JPATH_PLATFORM . "/$name";

So the extension name will come from the manifest.name and not from the manifest.libraryname. I changed my code from

<name>COM_EXAMPLE_TITLE</name>
<libraryname>example</libraryname>

to

<name>example</name>
<libraryname>COM_EXAMPLE_TITLE</libraryname>

and now it works properly. Interesting that every example I read about manifest.libraryname is completely wrong about this. The current version appears to have the same trait, so if this is a bug I think it is not fixed yet.

Note that you don't need the <languages> element, it is a Joomla 1.5 relic according to the documentation. It is important to keep the subdirectories and the naming convention. ln-LN/ln-LN.com_example.sys.ini. The manifest uses the *.sys.ini file for translations. I guess the other ini file is used by the running component.

So my manifest file looks like this:

<extension type="component" version="3.4" method="upgrade">

    <name>example</name>
    <libraryname>COM_EXAMPLE_TITLE</libraryname>
    <creationDate>January 2017</creationDate>
    <author>inf3rno</author>
    <authorEmail>xxx@gmail.com</authorEmail>
    <license>MIT</license>
    <version>0.0.9</version>
    <description>COM_EXAMPLE_DESCRIPTION</description>

    <scriptfile>installer.php</scriptfile>

    <files>
        <filename>example.php</filename>
        <folder>views</folder>
        <folder>src</folder>
        <folder>media</folder>
        <folder>language</folder>
    </files>

    <administration>
        <menu>COM_EXAMPLE_TITLE</menu>
        <files>
            <filename>example.php</filename>
            <folder>src</folder>
            <folder>media</folder>
            <folder>language</folder>
        </files>
    </administration>

</extension>

and I put the language files to subfolders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.