Actions

J2.5

Making non-core language packs

From Joomla! Documentation

Revision as of 12:00, 9 May 2012 by Mahagr (Talk | contribs)

To make a non-core language pack in 2.5 is quite different from making a Core pack.

http://docs.joomla.org/Making_a_Language_Pack_for_Joomla_1.6

The type of package is a "file" type.

Here is a typical xml including installing ini files into the administrator and site CORE default language folders for one language and one extension only. Many languages and many extensions can be included.


<?xml version="1.0" encoding="utf-8"?>
<extension type="file" version="2.5" method="upgrade">
 
        <!-- Please use a unique name to make uninstall to work. Should be identical to your manifest filename. -->
        <name>lang_extensionname_fr-FR</name>
        <author>French Translation Team</author>
        <creationDate>24 Janvier 2012</creationDate>
        <copyright>(C) 2005-2012 Whoever</copyright>
        <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
        <authorEmail>info@whoever</authorEmail>
        <authorUrl>http://www.myextension.org</authorUrl>
        <version>1.0.0</version>
        <description>This fr-FR lang pack for myextension has been installed successfully</description>
 
        <!-- Fileset definition -->
        <fileset>
 
                <!-- back-end -->
                <files folder="admin/fr-FR" target="administrator/language/fr-FR">
                        <filename>fr-FR.com_myextension.ini</filename>
                        <filename>fr-FR.com_myextension.sys.ini</filename>
                        <filename>fr-FR.plg_system_myextension.ini</filename>
                        <filename>fr-FR.plg_system_myextension.sys.ini</filename>
                </files>
 
                <!-- front-end -->
                <files folder="site/fr-FR" target="language/fr-FR">
                        <filename>fr-FR.com_myextension.ini</filename>
                        <filename>fr-FR.com_myextension.sys.ini</filename>
                        <filename>fr-FR.mod_myextension.ini</filename>
                        <filename>fr-FR.mod_myextension.sys.ini</filename>
                </files>
        </fileset>
</extension>

The .zip in this case is composed of the xml above and 2 folders: site and admin, each of them containing a fr-FR folder with the ini files.

lang_extensionname_fr-FR.xml

site/fr-FR/ + all ini files

admin/fr-FR/ + all ini files

The result is the installation of the ini files in an existing fr-FR folder or creating one if does not exist.

It has no impact on existing files. Uninstalling the "File" pack (Extensions Manager=>Manage=>Filter by "file") will only uninstall the ini files listed.

NOTE: In 2.5, except if one uses a specific script, the language xx-XX folders will always be created if they do not already exist.

Make it multi-language

If you want to pack all the available languages into one installable file, but want to be able to use separate file extensions (as explained above) to be able to uninstall or install them separately, a package with a small script is needed.

pkg_kunena_languages.xml (in our example):

<?xml version="1.0" encoding="utf-8"?>
<extension type="package" version="2.5" method="upgrade">
 
        <!-- Put anything into here, name is only shown in extension manager. -->
        <name>Kunena Language Pack</name>
 
        <!-- Filename without "pkg_" prefix. Must be unique or uninstall breaks. -->
        <packagename>kunena_languages</packagename>
 
        <version>2.0.0</version>
        <creationDate>2012-05-09</creationDate>
        <author>Kunena Team</author>
        <authorEmail>kunena@kunena.org</authorEmail>
        <authorUrl>http://www.kunena.org</authorUrl>
        <copyright>(C) 2008 - 2012 Kunena Team. All rights reserved.</copyright>
        <license>GNU/GPL</license>
        <description>Language pack for Kunena forum component.</description>
 
        <scriptfile>install.script.php</scriptfile>
        <files folder="language">
                <!-- Content will be added by our installer script -->
        </files>
</extension>

install.script.php:

<?php
defined( '_JEXEC' ) or die();
 
jimport( 'joomla.filesystem.file' );
jimport( 'joomla.filesystem.folder' );
jimport( 'joomla.filesystem.archive' );
jimport( 'joomla.installer.installer' );
 
class pkg_kunena_languagesInstallerScript {
 
        public function uninstall($parent) {
                // Remove languages.
                $languages = JFactory::getLanguage()->getKnownLanguages();
                foreach ($languages as $language) {
                        echo $this->uninstallLanguage($language['tag'], $language['name']);
                }
        }
 
        public function preflight($type, $parent) {
                if (!in_array($type, array('install', 'update'))) return true;
 
                $app = JFactory::getApplication();
 
                // If you want, you can detect your extension in here and fail with a message if it is not installed.
 
                // Get list of languages to be installed. Only installs languages that are found in your system.
                $source = $parent->getParent()->getPath('source').'/language';
                $languages = JFactory::getLanguage()->getKnownLanguages();
                $files = $parent->manifest->files;
                foreach ($languages as $language) {
                        $search = JFolder::files($source, $language['tag']);
                        if (empty($search)) continue;
                        // Generate something like <file type="file" client="site" id="com_kunena_fi-FI">com_kunena_fi-FI_v2.0.0.zip</file>
                        $file = $files->addChild('file', array_pop($search));
                        $file->addAttribute('type', 'file');
                        $file->addAttribute('client', 'site');
                        $file->addAttribute('id', preg_replace('#('.$language['tag'].').*#', '\1', $file););
                        echo sprintf('Installing language %s - %s ...', $language['tag'], $language['name']) . '<br />';
                }
                if (empty($files)) {
                        // No packages to install: replace failure message with something that's more descriptive.
                        $app->enqueueMessage(sprintf ( 'Your site is English only. There\'s no need to install language pack.' ), 'notice');
                        return false;
                }
 
                return true;
        }
 
        public function uninstallLanguage($tag, $name) {
                $table = JTable::getInstance('extension');
                $id = $table->find(array('type'=>'file', 'element'=>"com_kunena_{$tag}"));
                if (!$id) return;
 
                $installer = new JInstaller();
                $installer->uninstall ( 'file', $id );
        }
}

Then just have all the zip files (or installable directories) under language folder.