21309 Posts in 5738 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 1379 Views |
-
Duplicate entire website into new language!

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! -
Re: Duplicate entire website into new language!

11 November 2010 at 5:37am Last edited: 11 November 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;
} -
Re: Duplicate entire website into new language!

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
-
Re: Duplicate entire website into new language!

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 -
Re: Duplicate entire website into new language!

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 pagedoes it make sense now?
-
Re: Duplicate entire website into new language!

11 November 2010 at 11:00pm Last edited: 11 November 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 ;)
-
Re: Duplicate entire website into new language!

11 November 2010 at 11:12pm Last edited: 11 November 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
-
Re: Duplicate entire website into new language!

11 November 2010 at 11:38pm Last edited: 12 November 2010 3:19am
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 codego 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 tofunction 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
| 1379 Views | ||
| Go to Top | Next > |


