In an upcoming project multilingual XML imports might save me quite some time, so though I knew that things had changed recently (regarding importableField and prepareImportValue) and though my PHP Skills are quite limited I played around a little bit to see if I could set up a quick hack to get things working.

Well - I couldn't - and so I thought I might ask for some help here...

My Setup looks like this:

Test XML:

        <title>Multilingual Import Test</title>
            <value-en>Test EN</value-en>
            <value-de>Test DE</value-de>

I wrote a short prepareImportValue-function for the multilingual field and quickly faced the first problem - I couldn't call FLang::getAllLangs() inside of that function - So I simply hardcoded my two languages to arrange the data the right way - and that's what I came up with:

public function prepareImportValue($data, $mode, $entry_id = null) {

    $message = $status = null;

    $langs = array(
        '0' => 'en',
        '1' => 'de'

    $data_multilang = array();

    foreach($data as $key => $value){
        $data_multilang[$langs[$key]] = $value;

    $data = $data_multilang

    return $this->processRawFieldData($data, $status, $message, true, $entry_id);       


This seemed to do what I wanted and gave me the following result for $data:

Array (
    [en] => Test EN
    [de] => Test DE

But after passing that array to processRawFieldData I ran into exactly the same Problem there - FLang::getAllLangs() didn't return anything and so the multilingual data wasn't processed correctly. That's the point there I thought help might be useful, as I simply have no clue what the right way to call/include that FLang-thing in this context would be.

Any help would be appreciated - thanks!

Hi Roman,

I just did this to a certain extent... but I customised the Multilingual Field on my local copy; and I outputted the data from the older source in a slightly different format I think.

I can try pick it up tomorrow and send over a draft of the function. I'm sure its not perfect and you'll need to adjust since I used a different input XML format.

That's great to hear gunglien - would love to see your approach! Concerning the XML-structure I'm completely flexible - the above snippet was just meant for testing.

I just noticed that you already posted an issue concerning the general task of multilingual XML Import on github - got any feedback? Would be great to achieve general compatibility between the XML Importer and all multilingual fields.

But this may have to wait for an update of the XML Importer and the integration of modes into the documentation of the prepareImportValue function

Actually the version I have is for 2.3.1 so the function signature is slightly different. If you're importing for yourself you could technically 'ignore' whatever value the mode passes. Attached find the source of the prepareImportValue.

public function prepareImportValue($value, $entry_id){
    //initialize frontend localisation as not initiated
    $langs = FLang::getLangs();
    if (empty($langs)){
        $flExt = ExtensionManager::create('frontend_localisation');
        $langs = FLang::getLangs();
    $text= $value[0];
    $text= str_replace('&nbsp;',' ',html_entity_decode($value[0]));

    $xml = @simplexml_load_string($text);
    if (!$xml){

        //use this for the normal articles
        $xml = @simplexml_load_string(str_replace('&','&amp;',$text));
        if (!$xml){
            $text= str_replace('&','&amp;',$text);
            $text= iconv("UTF-8", "UTF-8//IGNORE", $text);
            $xml = simplexml_load_string($text);
    $result = array();
    foreach( $langs as $lc ){
        $node = $xml->xpath("//value[@lang='{$lc}']");
        $result[$lc] = (string)$node[0];
    return $result;

My XML structure looks like this, and I chose to match the content node

        <value lang="en">Value</value>

thanks alot - This looks like a great starting point for me!

I think this is the part I were missing:

if (empty($langs)){
    $flExt = ExtensionManager::create('frontend_localisation');
    $langs = FLang::getLangs();

I'll give it a try later this day and let you know if it works for me.

could be it took me some time to find out what was going on. Basically since the importer runs in the back-end the Languages are not initialized; that check is done so its only initialized once :)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details