Pretty simple. Here's the plugin code:
<?php
// get the related language ID pairs that Babel puts in
$context=$resource->get('context_key');
$langlink=$resource->getTVValue('babelLanguageLinks');
$langs=explode(';', $langlink);
// if first Babel language key is "web" and we're in the Spanish context,
// then there is an English version
if(isset($langs[0]) && substr($langs[0], 0,3)=='web' && $context=='es') {
// see what Articles container the English version is in and assign this resource to the Spanish one
$res = $modx->getObject('modResource',substr($langs[0],4));
$parent= $res->get('parent');
if($parent==191) {
$res2 = $modx->getObject('modResource',$id);
$res2->set('parent',195);
$res2->save();
}
}
You would add additional blocks of "if($parent==NNN){ . . . }" for however many news sections you have going, setting the parent to the corresponding language's news resource id ("$res2->set('parent',NNN);"), and check off the system event "OnDocFormSave" to trigger the plugin. Set the value of $context in the line ". . . && $context=='es'" to whatever you're using for your second language. I could have gone a step further and had the script discover the ID of the Spanish Articles container, and would do that if I were to make this a publicly available plugin, but my needs were met for this project using just the code above.
[ed. note: rainbowtiger last edited this post 14 years, 2 months ago.]