Import multilingual content to lingua tables using PHP API

Is there a standard or recommended way (using the PHP APIs) of importing and/or managing multilingual content that is stored in Lingua tables? I’ve been looking for examples or documentation, but haven’t found anything that has helped.

I don’t know if there is a “recommended way”, but using the classes linguaSiteContent and linguaSiteTmplvarContentvalues with xPDO to create resource-content and tv-values in other languages should work.

<?php
//create a new resource
$doc = $modx->newObject('modDocument');
$doc->set('parent', 0);
$doc->set('pagetitle','Title');
$doc->set('alias','title');
$doc->set('template',1);
$doc->set('published',0);
$doc->setContent('Content');
$doc->save();

//set a TV
$doc->setTVValue('myTV', 'TV value');

//get ID from new resource
$doc_id = $doc->get('id');

//create resource in another language
$doc_fr = $modx->newObject('linguaSiteContent');
$doc_fr->set('resource_id', $doc_id);
$doc_fr->set('lang_id', 2); //id of language from database table 'modx_lingua_langs'
$doc_fr->set('parent', 0);
$doc_fr->set('pagetitle','Title (french)');
$doc_fr->set('alias','title-fr');
$doc_fr->set('content','Content (french)');
$doc_fr->save();

//set a TV in another language
$tv_fr = $modx->newObject('linguaSiteTmplvarContentvalues');
$tv_fr->set('lang_id', 2); //id of language from database table 'modx_lingua_langs'
$tv_fr->set('tmplvarid', 1); //id of TV 'myTV'
$tv_fr->set('contentid', $doc_id); //resource-id
$tv_fr->set('value', 'TV value (french)');
$tv_fr->save();

Take a look a the schema for the available fields.

1 Like

Thanks. That helps a lot.