discuzx插件教程11----插件模板和语言包的设计

[复制链接]
插件语言包创建语言包
  • 给插件创建语言包首先需要创建一个 data/plugindata/identifier.lang.php 文件,文件内容中包含 4 个数组,如下:
  1. <?php

  2. $scriptlang['identifier'] = array(
  3.   'english' => 'chinese',
  4.   ...
  5. );

  6. $templatelang['identifier'] = array(
  7.   'english' => 'chinese',
  8.   ...
  9. );

  10. $installlang['identifier'] = array(
  11.   'english' => 'chinese',
  12.   ...
  13. );

  14. $systemlang['identifier'] = array(
  15.   'file' => array(
  16.      'english' => 'chinese',
  17.      ...
  18.   ),
  19.   ...
  20. );

  21. ?>
复制代码
$scriptlang 为程序脚本文件的语言包。
$templatelang 为模版文件的语言包。
$installlang 为安装、升级、卸载脚本用的语言包。
$systemlang 为系统语言包(Discuz! X3 新增)。
如果插件不涉及某些类型的语言文字,变量可忽略。

  • 然后在插件基本设置中开启语言包选项后即可。

调用语言包模版中调用模板文件语言包,通过 {lang identifier:english} 方式调用。
程序脚本中调用脚本文件语言包,通过 lang('plugin/identifier', 'english') 方式调用。
安装脚本中调用安装脚本文件语言包,通过 $installlang 变量直接获取。如 $installlang['english']。
系统语言包用于替换系统语言包中的某些语言条目。

语言包导出创建好的语言包在插件导出后会自动导出到 XML 文件中,供插件作者转码后发放多编码版本的插件。如上例中导出的 XML 中会包含以下内容:
  1. <item id="language">
  2.         <item id="scriptlang">
  3.                 <item id="english"><![CDATA[chinese]]></item>
  4.         </item>
  5.         <item id="templatelang">
  6.                 <item id="english"><![CDATA[chinese]]></item>
  7.         </item>
  8.         <item id="installlang">
  9.                 <item id="english"><![CDATA[chinese]]></item>
  10.         </item>
  11.         <item id="systemlang">
  12.                 <item id="file">
  13.                         <item id="english"><![CDATA[chinese]]></item>
  14.                 </item>
  15.         </item>
  16. </item>
复制代码
data/plugindata/identifier.lang.php 文件不必在插件发布的时候导出,此文件仅供插件设计者模式时使用。
插件模板插件的模板统一放置到 source/plugin/identifier/template 目录下,程序脚本通过以下语句调用插件模板文件,如下例,调用 source/plugin/identifier/template/test.htm
  1. include template('identifier:test');
复制代码
模版中调用插件模版通过以下方法:
  1. {template identifier:test}
复制代码
模板的编写详见模板创建、解析原理详解

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 返回列表 发新帖

QQ|小黑屋|手机版|Archiver|南京做好站网络科技有限公司 ( 苏ICP备17019756号-1 )

GMT+8, 2025-8-27 15:18 , Processed in 0.042199 second(s), 21 queries .

快速回复 返回顶部 返回列表