Jump to:

23374 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Duplicating entire website into new language, get error :(

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

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

Page: 1
Go to End
Author Topic: 1296 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Duplicating entire website into new language, get error :( Link to this post

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

  • borriej
    Avatar
    Community Member
    267 Posts
  • Ironcheese
    Avatar
    Community Member
    33 Posts

    Re: Duplicating entire website into new language, get error :( Link to this post

    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. =)

    1296 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.