Search code examples
xmlmagentotranslationgettextpo

Has someone a script to extract specific strings from XML files to allow to translate them via CSV or PO files


That's my first question here, normally I provide answers ;-)

Well, I'm looking for a script to extract some specific strings set into system.xml, layout xml files or similar they are used by Magento to translate them. Example: labels, menu item or else.

I have a script to extract them from php and phtml files thanks to gettext and convert them to a Portable Object file, then, I use the PO file to translate the strings thanks to OmegaT Software and finally I have also a PHP CLI script to convert the translated files from PO to CSV files.

Magento translates these xml files by using the module and the element information provided thanks to the attribute "translate='element_to_translate'" and "module='mymodule'" placed in an element (block or action for example) internally via an helper.

Here an example of xml code that I want to extract to allow me to translate it. Here I would like to translate the value of the element "label" thanks to the module "sales", as you see below the attributes in the XML code could be helpful to extract this information:

<customer_account>
        <reference name="customer_account_navigation" >
            <action method="addLink" translate="label" module="sales"><name>billing_agreements</name><path>sales/billing_agreement/</path><label>Billing Agreements</label></action>

or an other example:

<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
                <action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
                <action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
                <action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
            </block>
        </reference>
</customer_account>

So if someone has a script which allows to extract them it will be great. Honestly I didn't have the time to create such a script because I used already lots of time to create the whole process for the translation which stay complicated. But if someone did already the job, it will be great to share it here. However if people search the script to do the conversion from CSV to PO and reverse, I can help although it is fundable on the web. I just made some cosmetic changes compared to the original version.

Thanks for your feedbacks.


Solution

  • I have made a module for extracting strings to translate directly to csv files, in Magento format. If I recall correctly it handles the config and system xml's, not sure about the layout though.
    Give it a try and feel free to improve it :)

    https://bitbucket.org/OSdave/languagecsv