I have this script to duplicate my website into a new language. It worked perfect a while ago, but now (on a different server much bigger sitetree) it wont work.
I get this error
[User Error] Translatable::createTranslation(): Please save your record before creating a translation
GET /sapphire/main.php?url=/dev/tasks/TranslatePages&
But i don't know what i need to save? :s Please help!
The script
<?php
class TranslatePages extends BuildTask {
protected $title = "Translate all Pages";
protected $description = 'Copys all Pages into another Language (Note: set $Locale and $newLocale!)'; // description of what it does
protected $Locale = 'en_US'; // language of the pages you want to translate
protected $newLocale = 'de_DE'; // the language it should get translated to
function run($request) {
$Pages = DataObject::get('SiteTree', "Locale = '".$this->Locale."'");
foreach ($Pages as $Page) {
if(!$Page->getTranslation($this->newLocale)) {
$newPage = $Page->createTranslation($this->newLocale);
//$newPage = createTranslation($this->newLocale);
$this->debugMessage('Translated '.$Page->Title.' from '.$this->Locale.' to '.$this->newLocale);
}
}
$this->debugMessage('Done');
}
protected function debugMessage($msg) {
if(!SapphireTest::is_running_test()) {
Debug::message($msg);
}
}
}