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

Duplicate entire website into new language!


Go to End


12 Posts   3449 Views

Avatar
borriej

Community Member, 267 Posts

11 November 2010 at 5:15am

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

Forum Moderator, 1899 Posts

11 November 2010 at 5:37am

Edited: 11/11/2010 10:51pm

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

Community Member, 267 Posts

11 November 2010 at 9:25pm

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

Community Member, 267 Posts

11 November 2010 at 9:37pm

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

Forum Moderator, 1899 Posts

11 November 2010 at 10:05pm

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

Community Member, 267 Posts

11 November 2010 at 11:00pm

Edited: 11/11/2010 11:02pm

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

Forum Moderator, 1899 Posts

11 November 2010 at 11:12pm

Edited: 11/11/2010 11:13pm

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

Community Member, 30 Posts

11 November 2010 at 11:38pm

Edited: 12/11/2010 3:19am

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