Jump to:

23481 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Duplicate entire website into new language!

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 2
Go to End
Author Topic: 1801 Views
  • borriej
    Avatar
    Community Member
    267 Posts

    Duplicate entire website into new language! Link to this post

    This is a big issue ;)

    How can I duplicate my entire Silverstripe 2.4.2 based English website into a new language?
    For example into German.

    I've got 5 languages - 100 pages per languages = 500 pages (!)

    So manually is hard labor! ;)

    Please share!
    Thx!

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Duplicate entire website into new language! Link to this post

    If you hand't left IRC so fast...

    I have a basic function that creates pages (see below) so...
    a) select your pages and then
    b) get automatic translation of the pages (how about this...http://code.google.com/apis/language/diacritize/v1/getting_started.html?)

       function makePage($pg,$URLSegment,$Title,$strContent,$bShowInMenus,$bShowInSearch,$iParentID=0)
       {
          $pg->URLSegment = $URLSegment;
          $pg->Title = $Title;
          $pg->Content = $strContent;
          $pg->ShowInMenus = $bShowInMenus;
          $pg->ShowInSearch = $bShowInSearch;
          $pg->ParentID = $iParentID;
          $pg->writeToStage('Stage');
          $pg->publish("Stage", "Live");

          return $pg->ID;
       }

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Duplicate entire website into new language! Link to this post

    Ok, so i paste this function in my page.php

    and then i can control this trough the CMS i think.

    I will test now

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Duplicate entire website into new language! Link to this post

    Hmm i don't understand how it works, can you post a manual on how to use?
    Can't see any extra tools in the CMS when adding this function to page.php

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Duplicate entire website into new language! Link to this post

    post a manual????

    it is a function - put it anywhere, call it with the specified values and it creates the page and makes it live... you'll need to modify it to specify locale... this solution still needs work from you as I outlined...

    a) select your pages and
    b) get automatic translation of the pages (how about this...http://code.google.com/apis/language/diacritize/v1/getting_started.html?)
    c) use makePage to create new page

    does it make sense now?

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Duplicate entire website into new language! Link to this post

    How do you call the function?

    something like this?

    class Page_Controller extends ContentController {

    function makePage() {
    return $this->makePage();
    }

    }

    And what do I fll in for $pg, $URLSegment,$Title,$strContent,$bShowInMenus,$bShowInSearch,$iParentID=-1

    Some help would be great ;)

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Duplicate entire website into new language! Link to this post

    how about...

    $this->makePage(new Page(),'myurlsegment','my page title','some content for the page',true,true);

    $pg is left open so that you can specficy a different page type, depending on what page type you want to create

  • Zauberfisch
    Avatar
    Community Member
    30 Posts

    Re: Duplicate entire website into new language! Link to this post

    blubb

    borriej you lazy person

    since you need to copy the pages to translate them, i think the best practice will be to use the existing createTranslation method
    (if needed to duplicate the pages and not translate them, there is also a function calls "duplicate" ($newpage = $Page->duplicate();))

    here the way i would try
    (i can't promise you that it will work, never tested, you should do a backup before you run my code

    go to /mysite/code

    create a new file

    <?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 translatet 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);
           $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);
          }
       }
    }

    don forget the set $Locale and $newLocale !

    then go to yoursite.com/dev/tasks and run this task, and see if it works

    greetings <°(((-<

    // Edit: fixed typos

    1801 Views
Page: 1 2
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.