This article illustrates the Jtext usage of Joomla language translation. Share to everyone for your reference, specific as follows:
Basic methods of Use:
Jtext is an object of multi-language translation in Joomla, and the most basic usage is as follows:
Jtext::_ (' LANGUAGE CODE ');
If it is a variable, it is used directly, such as:
$var = Jtext::_ (' LANGUAGE CODE ');
If you need to display it, you can use Echo's command to show it, which is most common in template files, such as:
echo jtext::_ (' LANGUAGE CODE ');
Language Pack File:
Joomla can support multiple languages, each language pack 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 of the traditional Chinese language pack is: languages/zh-tw/
Each language has a basic Language pack file that will be loaded in any of the Joomla programs, such as:
The English Language pack file is: En-gb.ini
The Traditional Chinese Language pack file is: Zh-tw.ini
Each language for each component (Component) will have a language pack file that 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 Com_stock language packs in Com_community, you can introduce them 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 Use methods:
If a variable is present in the statement to be translated, the jtext::sprintf () method is required to translate, and jtext::sprintf () supports the use of variables in the language pack, which can support up to 3 variables. The format of jtext::sprintf () is as follows:
jtext::sprintf (' LANGUAGE CODE ', $var 1, $var 2, $var 3);
The wording of the corresponding language pack:
LANGUAGE code= Language Code%1$s,%2$s,%3$s
Such as:
JomSocial a piece of code is written like this, need to pass the member link and name that video link three variables, the program code is this:
jtext::sprintf (' CC activities featured Video ', $ownerUrl, $ownerName, $VIDEOURL);
The corresponding language pack is written like this:
CC activities featured Video=<a href=\ "%1$s\" >%2$s</a> <a href=\ "%3$s\" > Video </a> is listed as a select.
More about Joomla interested readers can view the site topics: "Symfony Framework Introductory Course", "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "thinkphp Common Methods Summary", " Introduction to PHP object-oriented programming, "PHP string (String) Usage Summary", "Php+mysql Database Operations Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article is helpful to everyone based on the Joomla program design.