Question

I created my own section (say "Company") under admin system_config

<config>
    <sections>
        <company translate="label">
            <label>Company</label>
            <tab>service</tab>
            <frontend_type>text</frontend_type>
            <sort_order>400</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
        </company >
    </sections>
</config>

I created 2 modules adding their own group under Company section. Those groups are displayed as intended. Both modules are well configured to handle adminhtml translations.

Module 1 :

<config>
    <adminhtml>
        <translate>
            <modules>
                <company>
                    <files>
                        <default>Company_Module1.csv</default>
                    </files>
                </company>
            </modules>
        </translate>
    </adminhtml>
</config>

and Module 2 :

<config>
    <adminhtml>
        <translate>
            <modules>
                <company>
                    <files>
                        <default>Company_Module2.csv</default>
                    </files>
                </company>
            </modules>
        </translate>
    </adminhtml>
</config>

So here is my problem : I created Module 2 before Module 1. As long as Module 2 was alone in Company section, my strings were correctly translated. As soon as I created Module 1 and added its group under Company section, only Module 1 labels and comments were translated.

It appears that only Company_Module1.csv is used. Any string in Company_Module2.csv is ignored. If I copy my Company_Module2.csv content in Company_Module1.csv file, then Module 2 is now correctly translated. It's very weird because I explicitly configured Module 2 to translate from Company_Module2.csv and not from Company_Module1.csv.

Can someone explain this behavior ? Eventually this will help me understand what I did wrong and fix it. Thanks !

Was it helpful?

Solution

To understand this behavior you need to know how Magento reads its configuration files.

First, all XML files are merged into one big structure. The result looks like this:

<config>
    <adminhtml>
        <translate>
            <modules>
                <company>
                    <files>
                        <default>Company_Module1.csv</default>
                        <default>Company_Module2.csv</default>
                    </files>
                </company>
            </modules>
        </translate>
    </adminhtml>
</config>

Then most values are either accessed via XPath or converted to an associative array structure. This structure would be something like

'files' => array(
    'default' => 'Company_Module1.csv',
    'default' => 'Company_Module2.csv',
 )

But an array cannot have the same key twice, so it ends up with only one value.

Solution

Always use unique identifiers in your config files, wherever you can choose them on your own.

It should be:

<config>
    <adminhtml>
        <translate>
            <modules>
                <company_module1>
                    <files>
                        <default>Company_Module1.csv</default>
                    </files>
                </company>
            </modules>
        </translate>
    </adminhtml>
</config>

and

<config>
    <adminhtml>
        <translate>
            <modules>
                <company_module2>
                    <files>
                        <default>Company_Module2.csv</default>
                    </files>
                </company>
            </modules>
        </translate>
    </adminhtml>
</config>

Also, in system.xml, you did not specify which module should be used, this might give you unexpected behaviour if there are conflicting translations. Better:

    <company translate="label" module="Company_Module1">

But this is not related to your problem

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top