In this tutorial you will learn how to make custom text support multi-languages. All default text in the template is already setup in this way.
As an example we'll translate the "Free Domain Name" title in the company.php page.
Firstly open the following files:
/templates/YOUR_TEMPLATE/company.tpl (the editable content for the company.php page - in some templates this is already setup to support multi-languages thus in the file below)
/modules/addons/zomex_template_manager/lang/english.php (contains the English translations)
Finding the text to translate
In the company.tpl the title uses a Heading 3 HTML tag:
Creating the translation in the English file
Open the English.php file and paste the following code at the bottom:
This is the format required in all language files. Between the two '' you'll see domaintitle, this is used to reference and load this specific translatation in the template files where specified. On the right side between the two "" you'll see Free Domain Name, this is the exact text you'd like to display in the template (when English is selected as a language).
Making the text load from the English file
Now we've got the correct translation in the english.php file it's time to change the company.tpl file to load this text from the language files. To do this edit the HTML from:
The text after the . must match the reference you added in the language file. In this case we used domaintitle.
Now whenever your visitor has the English language selected the above code will load the translation from the English.php file in this case Free Domain Name.
Setting up another language translation
Let's say you want to support French on your website. You'd need to add the same line you did in the English.php file but translate the displayed text to French. To do this open the following file (create if it doesn't exist but make sure you add the right code before your translations >?php):
/modules/addons/zomex_template_manager/lang/french.php (contains the French translations)
and paste the following to the bottom:
Notice that all we did was change Free Domain Name to Nom de domaine gratuit which is the French translation. The reference on the left must be exactly the same for all languages.
So how does this work?
Whenever you select a different language on the template the specific language translation is pulled from the matching language file. For example:
French = french.php
English - = english.php
Spanish = spanish.php
By having the same reference in each file but the unique translation to that language you can translate any text in any file in the same way we have for the header.tpl and footer.tpl files (already done for all templates).
Leave a comment
Let us know what you think!