Actions

User

Rvsjoen/tutorial/Developing a Template/Part 04

From Joomla! Documentation

< User:Rvsjoen‎ | tutorial/Developing a Template
Revision as of 06:23, 16 April 2012 by Rvsjoen (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contents

Adding translation

So, we would like our template to support translation, which essentially means that instead of hard-coding strings, we would like the strings to be read from translation files. This makes it very easy to provide multiple translations since all that has to be done to change the language is to read a different set of language files.

With your favorite editor, create the following file

language/en-GB/en-GB.tpl_helloworld.ini

TPL_HELLOWORLD="Hello World!"
TPL_HELLOWORLD_XML_DESCRIPTION="Hello World! template description"

As you can see, language strings are namespaced. This is a very good practice for avoiding that strings override each other. As an example these strings start with TPL_HELLOWORLD to indicate that they belong to our template.

In order to provide translation during the installation process, in the extension manager and in the menus, another language file is required in the backend. The difference between these two files can be daunting at first, but usually the sys.ini contains a lot less translation strings and this file is loaded in scenarios where the loaded component is not com_helloworld itself, but minimal translation is still needed.

With your favorite editor, create the following file

language/en-GB/en-GB.tpl_helloworld.sys.ini

TPL_HELLOWORLD="Hello World!"
TPL_HELLOWORLD_XML_DESCRIPTION="Hello World! template description"

With your favorite editor, edit the following file

templateDetails.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="template" client="site">
        <name>TPL_HELLOWORLD</name>
        <creationDate>Once upon a time</creationDate>
        <author>John Doe</author>
        <authorEmail>john.doe@example.org</authorEmail>
        <authorUrl>http://www.example.org</authorUrl>
        <copyright>Copyright Info</copyright>
        <license>License Info</license>
        <version>0.0.1</version>
        <description>TPL_HELLOWORLD_XML_DESCRIPTION</description>
        <files>
                <filename>index.php</filename>
                <filename>templateDetails.xml</filename>
                <folder>css</folder>
                <folder>language</folder>        </files>
        <positions>
                <position>header</position>
                <position>footer</position>
                <position>left</position>
        </positions>
</extension>

File listing

Testing your template

For details on how to install the template into your Joomla! site, refer to the information provided in Part 01.

Download this part

Articles in this series

This tutorial is supported by the following versions of Joomla!

Joomla 2.5