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.

General Questions

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

Duplicate entire website into new language!


Go to End
Reply

12 Posts   1827 Views

Avatar
borriej

11 November 2010 at 5:15am Community Member, 267 Posts

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!

Avatar
swaiba

11 November 2010 at 5:37am (Last edited: 11 November 2010 10:51pm), Forum Moderator, 1796 Posts

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

Avatar
borriej

11 November 2010 at 9:25pm Community Member, 267 Posts

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

Avatar
borriej

11 November 2010 at 9:37pm Community Member, 267 Posts

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

Avatar
swaiba

11 November 2010 at 10:05pm Forum Moderator, 1796 Posts

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?

Avatar
borriej

11 November 2010 at 11:00pm (Last edited: 11 November 2010 11:02pm), Community Member, 267 Posts

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

Avatar
swaiba

11 November 2010 at 11:12pm (Last edited: 11 November 2010 11:13pm), Forum Moderator, 1796 Posts

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

Avatar
Zauberfisch

11 November 2010 at 11:38pm (Last edited: 12 November 2010 3:19am), Community Member, 30 Posts

blubb

borriej you lazy person :P

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 :P

greetings <°(((-<

// Edit: fixed typos

Go to Top