Joomla教程:为Joomla插件创建语言包


当你为第三方的插件扩展做翻译时,通常是直接做到插件包中的,但有时你的语言包需要单独提交。后面这种情况下,也许会不大容易让使用者知道应该将语言包上传到哪里。

为了避免这种情况的发生,我们可以模仿Joomla 1.5的方式来创建一个用于Joomla 1.5 native的语言包安装插件。你需要将一些.ini文件与一个.xml文件(install.xml)压缩成为一个可被支持的档案类型其中.xml文件的代码如下(此代码对应管理后台的翻译):

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" client="administrator" type="language" method="upgrade">
<tag>xx-XX</tag>
<version>1.0</version>
<creationDate>YYYY-MM-DD</creationDate>
<author>Your Name</author>
<name>YourLanguage</name>
<authorEmail>
yourmail@example.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it </authorEmail>

<authorUrl>http://www.example.com/</authorUrl>
<copyright>Copyright (C) YYYY Copyright Owner. All rights reserved.</copyright>
<license>LicenseType</license>
<description>[Language name] translation for [extension_name]</description>
<files>
<filename>xx-XX.[extension_name].ini</filename>
</files>
<params />
</install>

如代码所示,最好添加method="upgrade"参数,以使将来能够比较容易的安装新版本的语言包;如果该参数未指定,那么将来升级时,安装程序将无法覆盖旧的语言文件,导致出错。

如果你也翻译了插件的前台页面,那么需要另外创建一个新的语言包。其中.xml文件(install.xml)的代码和上面的相同,只需将下面这行:

    <install version="1.5" client="administrator" type="language" method="upgrade">

修改为:

    <install version="1.5" client="site" type="language" method="upgrade">

在Joomla 1.5.4版本之后,用于某插件的管理后台和站点前台的语言包可以很容易的通过一个单一文件进行安装了;你可以通过以下的代码模板创建这样一个语言包安装器:

 <?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="language" client="both" method="upgrade">
<name>YourLanguage</name>
<tag>xx-XX</tag>
<version>1.0</version>
<creationDate>YYYY-MM-DD</creationDate>
<author>Your Name</author>
<authorEmail>youremail@example.com</authorEmail>
<authorUrl>http://www.yoursite.com/</authorUrl>
<copyright>Copyright (C) YYYY Copyright Owner. All rights reserved.</copyright>
<license>License Type</license>
<description>[Language name] translation for [extension_name]</description>
<administration>
<files folder="admin">
<filename>xx-XX.[extension_name].ini</filename>
</files>
</administration>
<site>
<files folder="site">
<filename>xx-XX.[extension_name].ini</filename>
</files>
</site>
<params />
</install>

对于这样的语言包安装器,你需要创建名为"admin"和"site"的文件夹,分别包括前后台所需的语言文件;install.xml需要放在在 这两个文件夹外面。由于Joomla 1.5.6修正了一些关键性的错误,导致升级成为了必须,所以我们推荐使用这种单一语言包安装器的模式。

我们可以为那些用于Joomla 1.5 native的,通过MVC模式进行开发的插件来创建这种类型的语言包。

使用者可以在站点管理后台的扩展管理中的Install中安装这样的语言包;语言包中所包括的语言文件会自动被上传到正确的路径中。

对于译者来说,这种方式可以允许他们在语言文件的头部加入译者信息,让使用者了解到如何与他们取得联系;对于插件开发者来说,他们不必再为那些用于Joomla 1.0的插件创建语言包安装功能了。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3