在joomla(2.5)系统插件安装过程中加载语言文件 [英] Load language file during joomla (2.5) system plugin installation

查看:76
本文介绍了在joomla(2.5)系统插件安装过程中加载语言文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装系统插件(在Joomla 2.5中)期间,我很难显示本地化的字符串.在xml文件中使用本地化字符串的正常"方式似乎无效,(请参见其他问题:基于语言的安装说明).

I'm having a real hard time showing a localized string during the installation of a system plugin (in Joomla 2.5). The "normal" way with localized strings in the xml file doesn't seem to work, (see this other question: Language based installation description).

我现在尝试了那里提出的方法,以通过安装脚本显示描述.这种工作方式(我可以成功地回显文本),但是,我也不能在那里进行本地化-在调试语言时,它表明plugin.sys.ini尚未加载.我尝试手动加载文件,但是加载任何插件语言文件均未成功. 这是我到目前为止(在名为setupscripts.php的文件中)得到的:

I now tried the way proposed there, to show the description via the install scripts. This kind of works (I can echo text successfully), however, I also can't localize there - when debugging the language it shows that the plugin.sys.ini is not loaded yet; I tried to manually load the file, but had no success with loading any of my plugin language files. This is what I got so far (in a file named setupscripts.php):

<?php // no direct access
defined('_JEXEC') or die('Restricted access');

class plgsystemmyplgnameInstallerScript {

    static function loadLanguage() {
        $lang =& JFactory::getLanguage();
        $lang->load('plg_system_myname', JPATH_ADMINISTRATOR);
    }

    function install($parent)
    {
        self::loadLanguage();
        echo JTEXT::_("PLG_MYNAME_TEST_TEXT");
    }
    function uninstall($parent)
    {
        self::loadLanguage();
        echo JText::_('PLG_MYNAME_UNINSTALL_TEXT');
    }
    function update($parent)
    {
        self::loadLanguage();
        echo JText::_('PLG_MYNAME_UPDATE_TEXT');
    }
    function preflight($type, $parent) {}
    function postflight($type, $parent) {
        self::loadLanguage();
        echo JText::_('PLG_MYNAME_INSTALL_TEXT');
    }
}

但是我只得到?? PLG_MYNAME_TEST_TEXT? ?? PLG_MYNAME_INSTALL_TEXT ?? (在安装过程中打开了语言调试)...奇怪的是,页面底部未翻译的字符串"下的语言调试功能显示为无"(如果不是经过尝试但失败了,问号来自何处?翻译???).

But I only get ??PLG_MYNAME_TEST_TEXT?? ??PLG_MYNAME_INSTALL_TEXT?? (language debugging is turned on) during installation... weirdly enough, the language debug feature at the bottom of the page under "untranslated strings" shows "None" (where do the question marks then come from if not from a tried but failed translation???).

尝试了一些变体(在插件名称末尾使用.sys,因为我实际上认为安装字符串应位于.sys.ini文件中,而没有第二个参数(保留默认值),但是没有运气-没有错误,日志中没有任何内容(实际上我的日志文件不存在,可能还没有条目?可以用Joomla设置日志级别吗?).但是从来没有加载任何文件("loaded"下没有任何更改)语言文件".

Tried some variations of it (with .sys at the end of the plugin name, since I actually think the setup strings should be in the .sys.ini file, without the second parameter (leaving it default), but no luck - no error, nothing in the log (in fact my log file isn't existing, probably there was no entry yet? can one set the log level with Joomla?). But never is there any file loaded (nothing changes under "loaded language files".

有人知道如何正确加载语言吗?

Anybody got an idea how to load the language properly?

在设置过程中加载语言时,是否需要考虑一些特别的事项?如果加载语言失败,为什么没有错误消息?是否可能需要将语言文件安装到特殊位置才能在安装过​​程中识别它们?我当前的xml如下所示:

Is there something special to consider when loading languages during setup? Why is there no error message if loading the languages fails? Do I maybe have to install the language files to a special location to get them recognized during installation? My current xml looks like this:

<extension version="2.5" type="plugin" group="system" method="upgrade">
<name>PLG_MYNAME</name>
<!-- ... author, copyright, version, .. --> 
<scriptfile>setupscripts.php</scriptfile>
<files>
    <filename plugin="myname">myname.php</filename>
    <filename>setupscripts.php</filename>
    <filename>index.html</filename>
    <folder>sql</folder>
</files>
<!-- ... install->sql->file ... -->
<!-- ... uninstall->sql->file ... -->
<!-- ... update->schemas->schemapath ... -->
<languages [folder="admin"]>
   <language tag="en-GB">en-GB.plg_system_myname.ini</language>
   <language tag="en-GB">en-GB.plg_system_myname.sys.ini</language>
   <!-- ... other languages ... -->
</languages>
<!-- ... config->fields->fieldset->field ... -->
</extension>

(folder ="admin"周围的方括号表示我尝试使用此属性,也尝试不使用此属性.它不会更改任何内容.)

(the square brackes around folder="admin" are supposed to indicate that I tried both with and without this attribute. It doesn't change anything).

推荐答案

最后,我发现了如何真正做到这一点.在Google Joomla开发人员小组中进行的彻底搜索提出了这个非常相似的问题.

Finally I found out how to really do it. A thorough search in the google Joomla dev group brought up this very similar question.

基本上,语言文件似乎需要驻留在单独的语言文件夹中,并且文件"部分还需要引用它们.我的xml现在看起来像这样:

Basically, the language files need to reside in a separate language folder it seems, and the files section also needs to reference them. My xml now looks like this:

<!-- ... everything else stayed the same, except: -->
<files>
    <filename plugin="myplg">myplg.php</filename>
    <filename>index.html</filename>
    <folder>language</folder>
    <folder>sql</folder>
</files>
<languages folder="language">
        <language tag="en-GB">en-GB/en-GB.plg_system_myplg.ini</language>
        <language tag="en-GB">en-GB/en-GB.plg_system_myplg.sys.ini</language>
        <!-- .. other languages ... ->
</languages>
<!-- ... rest of the xml file ... -->

语言文件现在都位于单独的子文件夹中……它们被复制到与以前完全相同的位置(管理员/语言//...),但是现在XML的描述也已本地化!

The language files are now all in separate subfolders... they get copied to the exact same location as before (administrator/language//...), but now the description from the XML is also localized!

我发现非常奇怪的是,有太多种指定语言文件的方法,除了安装的一个极端情况外,所有这些方法基本上都可以使用...

I find it very weird that there are so many ways to specify language files, which all basically work except for the one corner case of the installation...

希望这会帮助其他为此苦苦挣扎的人!

Hope this will help other people struggling with this!

这篇关于在joomla(2.5)系统插件安装过程中加载语言文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆