Git Product home page Git Product logo

Comments (12)

sheadawson avatar sheadawson commented on July 30, 2024

I have zero experience with translatable, sorry! Let us know how you go

from silverstripe-blocks.

thezenmonkey avatar thezenmonkey commented on July 30, 2024

Here's a quick working GIST to support basic translatable fucntionality. It will create translated versions of blocks when translatlating a page

https://gist.github.com/thezenmonkey/6e6730023af553f12e3ab762ace3b08a

from silverstripe-blocks.

sheadawson avatar sheadawson commented on July 30, 2024

Thanks for that, I've added a note and link to your gist in the readme :)

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

How do you apply the posted TranslatableBlockPage?

from silverstripe-blocks.

thezenmonkey avatar thezenmonkey commented on July 30, 2024

You need to add the Translatable extension to the Block. Once thats done either add the onTranslatableCreate() from the gist to your Page class or apply the DataExtension to your SiteTree. The reason it's seperate is because you may need modify the onTranslatableCreate() depending on your specfic requirements.

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

For me that crashes at

$block = $originalBlock->createTranslation($translatedPage->Locale);

Telling me that ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'createtranslation' does not exist on 'ImageOnlyBlock'. (ImageOnlyBlock is one of my custom blocks.)

Any ideas what I'm doing wrong? I'm using Silverstripe 3.3 and the most recent version of the silverstripe-blocks and silverstripe-translate plugin.


EDIT:

That's what I'm doing in my _config.php (the relevant part of it):

// Enable Translateable module
Translatable::set_default_locale('de_CH');
SiteTree::add_extension('Translatable');
SiteConfig::add_extension('Translatable');

// Add support for translatable Blocks
SiteTree::add_extension('Page', 'TranslatableBlockPage');

So createTranslation should be available when TranslatableBlockPage::onTranslatableCreate() is triggered?

from silverstripe-blocks.

thezenmonkey avatar thezenmonkey commented on July 30, 2024

You also need to add the translatable extension to both the page and the block

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

Thank you, that's all I need. I just added Block::add_extension('Translatable'); and now it works.

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

While with that configuration every seems to work, it's still not possible to create new blocks and add it to another language then the default language.

For my case: At first all pages where created in the primary language de_CH and then I used the Create Translation button to translate all of them to en_US. Everything seem to work back then. Now I tried to create a new block on an en_US page and when I saved the block I didn't get any error message, but the block didn't appear in the front nor in the backend. So I looked up the block in the backend and found that it has the locale field set to de_CH even if it was attach to an en_US page. Once I manually changed the locale to the correct one, the block got displayed.

Can anybody give me an hint about how to write a DataExtension which fixes that newly created blocks get assigned the correct locale?

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

No ideas? I would just need to know where to hack in to correctly set the locale field on the newly created block. Isn't there a way to catch "new block created" event using a DataExtension?

from silverstripe-blocks.

thezenmonkey avatar thezenmonkey commented on July 30, 2024

Current Locale should be assigned via the Translatable extension by default whenever you create a new translatable dataobject.

from silverstripe-blocks.

hohl avatar hohl commented on July 30, 2024

Thank you, I'll try if updating the translatable plugin helps (maybe just some bug in their plugin?) and then ask if they could help me with my issue.

However, all I found yet, was that the form for creating a new block already contains the wrong locale. (So the POST request for creating the block sends always the primary language.)

from silverstripe-blocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.