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

StackOverflow https://stackoverflow.com/questions/14141684

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.

有帮助吗?

解决方案

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

其他提示

Check out Bryan Schnabel's XML - XLIFF round-trip tool: http://sourceforge.net/projects/xliffroundtrip/

xliffRoundTrip automates a roundtrip between any XML file and XLIFF. It consists of 2 XSL files + Java source. The 1st transforms XML to XLIFF. The 2nd transforms that XLIFF back to the original XML, i.e., after a language translation on the XLIFF file.

Bryan is a long-time member of the OASIS XLIFF tech comm.

There are professional translation tools out there, like for example SDL Trados that do such things. With trados you would not convert it into csv, but into xliff, which is a standard format for translation files.

SDL Trados Studio allows you create custom rules to process xml files. SDL calls them 'file types'. See a basic introduction here: http://producthelp.sdl.com/kb/Articles/5274.html

File types allow you to specify which elements and attributes are (un)translatable.

SDL Trados Studio does not allow you evaluate the 'translatability' of an element on the basis of an attribute in parent element.

In other words:

  • if you always have to translate the label element: SDL Trados Studio can handle it if you create a file type. The translate attribute of the action element is useless.
  • if you don't always have to translate the label element, but want to evaluate it based on the translate attribute, you really need a script to preprocess (and postprocess afterwards). But since you're building your own xml file, I suppose you could build it so translatable content is in an identifiable element.

If you're looking for a free solution, check out Memsource. They allow exactly the same principle, but I'm less familiar with the exact procedure.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top