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

查看:13
本文介绍了在 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 设置日志级别吗?)但从来没有加载任何文件(加载"下没有任何变化语言文件".

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天全站免登陆