Skip to main content
added 335 characters in body
Source Link
inf3rno
  • 391
  • 1
  • 18

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>[email protected]</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.

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>[email protected]</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.

Source Link
inf3rno
  • 391
  • 1
  • 18

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.