Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Duplicating entire website into new language, get error :(


Go to End


3 Posts   1799 Views

Avatar
borriej

Community Member, 267 Posts

10 February 2011 at 4:10am

Edited: 10/02/2011 4:16am

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);
      }
   }
}

Avatar
borriej

Community Member, 267 Posts

14 February 2011 at 8:12am

up

Avatar
Ironcheese

Community Member, 36 Posts

21 October 2011 at 10:31pm

I know its a late reply, but i just ran into the same problem.

The reason i got this error was because of orphaned pages in my sitetree. One page was still inside the DB but had no parent. That broke the createTranslation function.

Hope this helps someone with the same problem. =)