官方系列教材 - H计划

代码生成器

在做组件开发的时候,我们需要加载组件的语言文件。默认情况下,系统会自动的加载当前组件的语言文件。但是,一些特殊的情况下,我们需要加载非当前组件的语言文件,此时可以使用JLanguage类的load方法。这个方法可以让我们在任何地方加载需要的语言文件。

简单的实例代码


// STEP 1 ://加载语言文件
JFactory::getLanguage()->load('com_zmaxmsg',JPATH_ADMINISTRATOR ."/components/com_zmaxmsg");

上面的代码就会加载后台com_zmaxmsg这个组件的语言文件。系统会在后台的componets/com_zmaxmsg 这个目录下面寻找当前的language语言文件。

load方法支持5个参数,第一个参数是需要加载的扩展的名称,第二个参数是语言文件的路径。第三个是需要加载的语言类型。详细的说明如下:

	
#load( string $extension = 'joomla', string $basePath = JPATH_BASE, string $lang = null, boolean $reload = false, boolean $default = true )
Loads a single language file and appends the results to the existing strings

Parameters
$extension
string - $extension The extension for which a language file should be loaded.
$basePath
string - $basePath The basepath to use.
$lang
string - $lang The language to load, default null for the current language.
$reload
boolean - $reload Flag that will force a language to be reloaded if set to true.
$default
boolean - $default Flag that force the default language to be loaded if the current does not exist.
Returns
boolean - True if the file has successfully loaded.
Since
11.1

 

更多关于JLanguage类


JLanguage类主要的功能是负责处理系统语言相关的问题。

具体的类实现文件可以参考http://www.joomlachina.cn/joomla/api/class-JLanguage.html

 

作者: 樱木花道

Joomla程序员,从J1.5到J4.x始终都在做Joomla相关开发定制工作,有超过10年行业经验,国内Joomla扩展开发商ZMAX团队的核心成员

作者网站:ZMAX程序人

评论 (0)

  • 最新在前
  • 最佳在前

第1章 经验分享

第2章 专题教程

第3章 扩展推荐

第13章 扩展更新日志