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.

All other Modules /

Discuss all other Modules here.

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

Translatable not copying images to translated page


Go to End


4 Posts   1547 Views

Avatar
Apc204

Community Member, 12 Posts

14 January 2015 at 4:56am

Hi, I've recently started using the translatable module on my silverstripe site, and came across the following problem. When I select a page in the CMS and create a new translation, all of the CMS fields are copied onto the new page - apart from Images/Upload fields. As my site features an awful lot of upload fields and will need many translations it is very time consuming to have to reselect all of the files for the upload fields after every page translation I make.

I had a search around and found a suggestion saying that the following code added to createTranslation() in Translatable.php would fix the issue.

 foreach( $originalPage->many_many() as $key => $className ){ 
		$newTranslation->{$key}()->addMany($originalPage->{$key}()->getIdList()); 
		} 
However I tried with no such luck.
Has anyone else encountered this problem and found a workaround?

Many thanks,
Adam.

Avatar
Apc204

Community Member, 12 Posts

9 February 2015 at 10:32pm

Still experiencing this issue, anyone else encountered this or found a solution?

Avatar
ntd

Community Member, 9 Posts

8 July 2015 at 3:53am

Edited: 08/07/2015 3:54am

Don't touch the original files: nobody will be able to help you anymore if you mess your modules up.

You can leverage the dedicated hook by adding something similar to the following code to your DataObject:

public function onTranslatableCreate($save) {
    $master = $this->getTranslation(Translatable::default_locale());
    foreach ($master->Files() as $master_file) {
        $image = $master_file->duplicate($save);
        $this->Files()->add($image);
    }
}

Avatar
Pyromanik

Community Member, 419 Posts

8 July 2015 at 10:50am

And also add the same code but for has_many too I guess. You'll need to clone each linked object though, because they can only have_one page to be related to (by nature of a has_many relationship)