模块翻译未翻译
我的模块中的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我记得当我的商店在开发模式下运行时遇到翻译问题。它背后有一个基本原理,可以让你更好地调试翻译或其他东西。
我相信具体情况是在开发模式下,遇到的第一个翻译被选中。非开发时,仅搜索特定模块。
比如说,你有模块 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.
有两件事可能会出错。第一个是您的 config.xml 节点错误,并且 Magento 不知道查找您的文件。第二个是您的节点正确,但 Magento 找不到您的文件,因为它位于错误的位置。
跳到以下文件中的以下方法
这是加载翻译文件的代码。使用
var_dump
或Mage::Log
添加一些临时调试。清除缓存,重新加载页面。检查文件的调试语句。如果您看到它列出,请确保它确实存在于文件系统上并且可读。
如果没有显示,则说明您的配置不正确。确保您的
config.xml
看起来像这样使用 模块列表模块 来确保您的模块实际上已加载到系统中。
祝你好运!
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
This is the code that loads translation files. Add some temporarily debugging using
var_dump
orMage::Log
.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 thisUse something like the Module List Module to make sure your module is actually loaded into the system.
Good luck!
测试一下。默认值可以从其他模块覆盖。
test this. Default can be overwrite from a other Modul.
您的 Namespace_Module.csv 应该有双引号字符串,并且双引号包含在转义中...
单引号似乎是合乎逻辑的方法,这意味着您不需要转义字符串中的双引号并提供更自然的字符串匹配,但单引号 csv将被完全忽略 - 在这方面浪费了一些时间。
请参阅 Mage_Core.csv 以供参考...
Your Namespace_Module.csv should have double quoted strings with and double quotes contained within escaped...
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...