开发者

Module translation is not translating

开发者 https://www.devze.com 2023-03-25 19:04 出处:网络
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 a

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>


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.


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!


    <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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消