Joomla language translation class Jtext Usage Analysis, joomlajtext

Source: Internet
Author: User

Joomla language translation class Jtext Usage Analysis, joomlajtext

This document describes the usage of Joomla translation class Jtext. We will share this with you for your reference. The details are as follows:

Basic usage:

Jtext is an object for multilingual translation in Joomla. The basic usage is as follows:

Jtext::_('LANGUAGE CODE'); 

If it is a variable, use it directly, for example:

$var = Jtext::_('LANGUAGE CODE'); 

If you need to display it, you can use the echo command to display it. This method is the most common in template files, such:

echo Jtext::_('LANGUAGE CODE');

Language Pack file:

Joomla supports multiple languages. The files in each language pack are stored in the ages folder as folders, for example:

The folder Name of the English Language Pack is: Ages/en-GB/

The folder Name of the traditional Chinese Language Pack is: Ages/zh-TW/

Each language has a basic language pack file, which is loaded in any program running in Joomla, for example:

English Language Pack: en-GB.ini

Traditional Chinese Language Pack file: zh-TW.ini

Each language of each Component has a Language Pack file, which is loaded only when the Component is running by default. For example:

The English Language Pack for com_community is: en-GB.com_community.ini

The Chinese Language Pack for com_community is: zh-TW.com_community.ini

How to reference Language Pack files across components:

To use a language pack for other components, you must first introduce the Language Pack for this component. For example, to use the com_stock Language Pack in com_community, use the following method:

$ Lang = & JFactory: getLanguage (); $ lang-> load ('com _ stock'); // The name of the component, that is, the middle part of the Language Pack file name: en-GB.com_stock.ini

Advanced usage:

If a variable appears in the statement to be translated, you need to use the JText: sprintf () method for translation. JText: sprintf () supports using variables in the Language Pack, A maximum of three variables are supported. The format of JText: sprintf () is as follows:

Jtext::sprintf('LANGUAGE CODE',$var1,$var2,$var3); 

The corresponding Language Pack is written as follows:

Language code = language code % 1 $ s, % 2 $ s, % 3 $ s

For example:

JomSocial has a piece of code written in this way. You need to input three variables: Member link and video link. The code of the program is written in this way:

JText::sprintf('CC ACTIVITIES FEATURED VIDEO', $ownerUrl, $ownerName, $videoUrl);

The corresponding Language Pack is written as follows:

Cc activities featured video = <a href = \ "% 1 $ s \"> % 2 $ s </a> <a href = \ "% 3 $ s \"> optional values </a> are listed as excellent candidates.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.