API16

JInstaller/parseLanguages

From Joomla! Documentation

< API16:JInstaller

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to parse through a languages element of the installation manifest and take appropriate action.


<! removed transcluded page call, red link never existed >

Syntax[edit]

parseLanguages($element, $cid=0)
Parameter Name Default Value Description
$element $element The xml node to process
$cid 0 $cid Application ID of application to install to

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/installer/installer.php

Importing[edit]

jimport( 'joomla.installer.installer' );

Source Body[edit]

public function parseLanguages($element, $cid=0)
{
        if ( ! $element instanceof JXMLElement || ! count($element->children())) {
                // Either the tag does not exist or has no children therefore we return zero files processed.
                return 0;
        }

        // Initialise variables.
        $copyfiles = array ();

        // Get the client info
        jimport('joomla.application.helper');
        $client = &JApplicationHelper::getClientInfo($cid);

        /*
         * Here we set the folder we are going to copy the files to.
         *
         * 'languages' Files are copied to JPATH_BASE/language/ folder
         */
        $destination = $client->path.DS.'language';

        /*
         * Here we set the folder we are going to copy the files from.
         *
         * Does the element have a folder attribute?
         *
         * If so this indicates that the files are in a subdirectory of the source
         * folder and we should append the folder attribute to the source path when
         * copying files.
         */
        $folder = (string)$element->attributes()->folder;
        if ($folder && file_exists($this->getPath('source').DS.$folder)) {
                $source = $this->getPath('source').DS.$folder;
        }
        else {
                $source = $this->getPath('source');
        }

        // Process each file in the $files array (children of $tagName).
        foreach ($element->children() as $file)
        {
                /*
                 * Language files go in a subfolder based on the language code, ie.
                 *
                 *              <language tag="en-US">en-US.mycomponent.ini</language>
                 *
                 * would go in the en-US subdirectory of the language folder.
                 *
                 * We will only install language files where a core language pack
                 * already exists.
                 */
                if ((string)$file->attributes()->tag != '')
                {
                        $path['src'] = $source.DS.$file;
                        if ((string)$file->attributes()->client != '')
                        {
                                // override the client
                                $langclient =& JApplicationHelper::getClientInfo((string)$file->attributes()->client, true);
                                $path['dest'] = $langclient->path.DS.'language'.DS.$file->attributes()->tag.DS.basename((string)$file);
                        }
                        else
                        {
                                // use the default client
                                $path['dest']   = $destination.DS.$file->attributes()->tag.DS.basename((string)$file);
                        }

                        // If the language folder is not present, then the core pack hasn't been installed... ignore
                        if (!JFolder::exists(dirname($path['dest']))) {
                                continue;
                        }
                }
                else
                {
                        $path['src']    = $source.DS.$file;
                        $path['dest']   = $destination.DS.$file;
                }

                /*
                 * Before we can add a file to the copyfiles array we need to ensure
                 * that the folder we are copying our file to exits and if it doesn't,
                 * we need to create it.
                 */
                if (basename($path['dest']) != $path['dest'])
                {
                        $newdir = dirname($path['dest']);

                        if (!JFolder::create($newdir))
                        {
                                JError::raiseWarning(1, 'JInstaller::install: '.JText::_('FAILED_TO_CREATE_DIRECTORY').' "'.$newdir.'"');
                                return false;
                        }
                }

                // Add the file to the copyfiles array
                $copyfiles[] = $path;
        }

        return $this->copyFiles($copyfiles);
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]