模块翻译未翻译

发布于 2024-11-27 20:10:04 字数 635 浏览 1 评论 0原文

我的模块中的 Magento 翻译遇到了一些问题,因为它不起作用。正如所有教程所说,它应该很容易。每个 app/locale/[xx_XX]/ 文件夹中都有一个 .csv 文件,并且 config.xml 中也有一个条目。我的模块中有一个助手,它也在 config.xml 中注册,我可以使用它。毕竟,我清除了所有缓存文件并重试。

我做错了什么或者我忘记了什么?

代码中的调用:

$str = Mage::helper('mymodule')->__('mystring');

在 config.xml 中(在前端、adminhtml 和全局命名空间中尝试了此块):

<translate>
    <modules>
        <Namespace_Module>
            <files>
                <default>Namespace_Module.csv</default>
            </files>
        </Namespace_Module>
    </modules>
</translate>

I got a little problem with Magento translation in my module, because it does not work. It should be easy as all tutorials saying. There is a .csv-file in every app/locale/[xx_XX]/ - folder and also an entry in config.xml. I have a helper in my module, which is also registered in config.xml and I can use it. After all, I cleared all cachefiles and tried again.

What did I wrong or what I forgot?

The call in code:

$str = Mage::helper('mymodule')->__('mystring');

And in config.xml (tried this block in frontend, adminhtml and global namespaces):

<translate>
    <modules>
        <Namespace_Module>
            <files>
                <default>Namespace_Module.csv</default>
            </files>
        </Namespace_Module>
    </modules>
</translate>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

早乙女 2024-12-04 20:10:04

我记得当我的商店在开发模式下运行时遇到翻译问题。它背后有一个基本原理,可以让你更好地调试翻译或其他东西。

我相信具体情况是在开发模式下,遇到的第一个翻译被选中。非开发时,仅搜索特定模块。

比如说,你有模块 A 和 B,它们都有术语“翻译这个”,在我的开发环境中,我从模块 A 获得了翻译,而在生产中,我从模块 B 获得了翻译。

不确定是什么样的术语你有,但这可能与你的问题有关。

I remember having translation problems when my shop ran in development mode. There was a rationale behind it, allowing you to better debug translations or something.

I believe the specific case was that in development mode, the first translation encountered was picked. In non-development, only the specific module is searched.

So say, you have module A and B, and they both have term "Translate this", in my development environment, I got the translation from module A, while in production, i got it from module B.

Not sure what kind of terms you have, but it could relate to your problem.

极致的悲 2024-12-04 20:10:04

有两件事可能会出错。第一个是您的 config.xml 节点错误,并且 Magento 不知道查找您的文件。第二个是您的节点正确,但 Magento 找不到您的文件,因为它位于错误的位置。

跳到以下文件中的以下方法

#File: app/code/core/Mage/Core/Model/Translate.php
protected function _loadModuleTranslation($moduleName, $files, $forceReload=false)
{
    foreach ($files as $file) {
        $file = $this->_getModuleFilePath($moduleName, $file);
        $this->_addData($this->_getFileData($file), $moduleName, $forceReload);
    }
    return $this;
}

这是加载翻译文件的代码。使用 var_dumpMage::Log 添加一些临时调试。

protected function _loadModuleTranslation($moduleName, $files, $forceReload=false)
{
    var_dump($moduleName);
    foreach ($files as $file) {
        var_dump('Start');
        var_dump($file);
        $file = $this->_getModuleFilePath($moduleName, $file);
        var_dump($file);
        $this->_addData($this->_getFileData($file), $moduleName, $forceReload);
        var_dump('End');
    }
    return $this;
}

清除缓存,重新加载页面。检查文件的调试语句。如果您看到它列出,请确保它确实存在于文件系统上并且可读。

如果没有显示,则说明您的配置不正确。确保您的 config.xml 看起来像这样

<config>
    <frontend>
        <translate>
            <modules>
                <Namespace_Module>
                    <files>
                        <default>Namespace_Module.csv</default>
                    </files>
                </Namespace_Module>
            </modules>
        </translate>
    </frontend>
</config>

使用 模块列表模块 来确保您的模块实际上已加载到系统中。

祝你好运!

There's two possible things that could be going wrong. The first is you've got your config.xml nodes wrong, and Magento doesn't know to look for your file. The second is you've got your nodes correct, but Magento can't find your file because it's in the wrong location.

Pop over to the following method in the following file

#File: app/code/core/Mage/Core/Model/Translate.php
protected function _loadModuleTranslation($moduleName, $files, $forceReload=false)
{
    foreach ($files as $file) {
        $file = $this->_getModuleFilePath($moduleName, $file);
        $this->_addData($this->_getFileData($file), $moduleName, $forceReload);
    }
    return $this;
}

This is the code that loads translation files. Add some temporarily debugging using var_dump or Mage::Log.

protected function _loadModuleTranslation($moduleName, $files, $forceReload=false)
{
    var_dump($moduleName);
    foreach ($files as $file) {
        var_dump('Start');
        var_dump($file);
        $file = $this->_getModuleFilePath($moduleName, $file);
        var_dump($file);
        $this->_addData($this->_getFileData($file), $moduleName, $forceReload);
        var_dump('End');
    }
    return $this;
}

Clear your cache, reload a page. Check your debugging statements for your file. If you see it listed, ensure that it actually exists on the file system, and that it's readable.

If it doesn't show up, that means you're configured incorrectly. Make sure your config.xml looks something like this

<config>
    <frontend>
        <translate>
            <modules>
                <Namespace_Module>
                    <files>
                        <default>Namespace_Module.csv</default>
                    </files>
                </Namespace_Module>
            </modules>
        </translate>
    </frontend>
</config>

Use something like the Module List Module to make sure your module is actually loaded into the system.

Good luck!

歌枕肩 2024-12-04 20:10:04
    <translate>
        <modules>
            <Namespace_Module>
                <files>
                    <Namespace_Module>Namespace_Module.csv</Namespace_Module>
                </files>
            </Namespace_Module>
        </modules>
    </translate>

测试一下。默认值可以从其他模块覆盖。

    <translate>
        <modules>
            <Namespace_Module>
                <files>
                    <Namespace_Module>Namespace_Module.csv</Namespace_Module>
                </files>
            </Namespace_Module>
        </modules>
    </translate>

test this. Default can be overwrite from a other Modul.

物价感观 2024-12-04 20:10:04

您的 Namespace_Module.csv 应该有双引号字符串,并且双引号包含在转义中...

"Translation String","Translated String"
"<a href=\"%s\">click here</a>","<a href=\"%s\">here clicked</a>"

单引号似乎是合乎逻辑的方法,这意味着您不需要转义字符串中的双引号并提供更自然的字符串匹配,但单引号 csv将被完全忽略 - 在这方面浪费了一些时间。

请参阅 Mage_Core.csv 以供参考...

Your Namespace_Module.csv should have double quoted strings with and double quotes contained within escaped...

"Translation String","Translated String"
"<a href=\"%s\">click here</a>","<a href=\"%s\">here clicked</a>"

Single quotes seems the logical approach meaning you would not need to escape the double quotes in the string and giving a more natural string match, but single quoted csv will be completely ignored - lost a bit of time on this.

See Mage_Core.csv for reference...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文