This paper describes the Jtext usage of Joomla language translation class. Share to everyone for your reference, as follows:
Basic methods of Use:
Jtext is an object of the multi-language translation in Joomla, and the most basic way to use it is as follows:
If it is a variable, it is used directly, such as:
If you need to display it, you can use the echo command to show it, which is most common in template files, such as:
echo jtext::_ (' LANGUAGE CODE ');
Language Pack files:
Joomla can support multiple languages, each language pack of files in the form of folders exist under the Languages folder, such as:
The folder name for the English language pack is: languages/en-gb/
The folder name for the traditional Chinese language pack is: languages/zh-tw/
Each language has a basic Language pack file, which will be loaded in any program running in Joomla, such as:
The English Language pack file is: En-gb.ini
The language pack file for Traditional Chinese is: Zh-tw.ini
Each language of each component (Component) will have a language pack file, which is loaded by default when the component is run, such as:
Com_community's English language pack is: En-gb.com_community.ini
Com_community's Chinese language pack is: Zh-tw.com_community.ini
How to reference a language pack file across components:
If you want to use a language pack for another component, you must first introduce the component's language pack before you can use it. If you want to use the Com_stock language pack in com_community, you can introduce it in the following ways:
$lang =& jfactory::getlanguage (); $lang->load (' Com_stock ');//The name of the component, which is the middle part of the language pack file name: En-gb.com_stock.ini
Advanced methods of Use:
If a variable appears in the statement to be translated, the jtext::sprintf () method is required for translation, and jtext::sprintf () supports the use of variables in the language pack, up to 3 variables can be supported. The format of jtext::sprintf () is as follows:
The wording of the corresponding language pack:
Such as:
JomSocial a piece of code is written like this, need to pass in the membership link and the name of the video link three variables, the code of the program is written like this:
jtext::sprintf (' CC activities FEATURED VIDEO ', $ownerUrl, $ownerName, $VIDEOURL);
The corresponding language pack is written in this way:
The video of CC activities FEATURED Video=%2$s is listed as a fine choice.
More about Joomla related content readers can view this site topic: "Symfony Framework Introductory Tutorial", "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Basic Tutorial", "thinkphp Common Methods Summary", " PHP Primer for object-oriented programming, PHP string Usage Summary, Introduction to PHP+MYSQL database operations, and PHP common database operations Tips Summary
It is hoped that this article is helpful to everyone based on Joomla program design.