Making a existing stream translatable
Created 6 years ago by dwains

Hi, I want to make a existing stream translatable. This is the original stream:

<?php
    protected $fields = [
        'title' => 'anomaly.field_type.text',
        'subtitle' => 'anomaly.field_type.text',
        'description' => [
            'type' => 'anomaly.field_type.wysiwyg',
            "config" => [
                "default_value" => '<p>Tekst</p>',
                "configuration" => "default",
                "line_breaks"   => true,
                "height"        => 25,
                "buttons"       => ["bold","italic","format","link","lists"],
                "plugins"       => ["source"],
            ],
        ],
        'link' => [
            'type'      => 'anomaly.field_type.relationship',
            'config'    => [
                'related' => 'Anomaly\PagesModule\Page\PageModel',
                'mode'  => 'lookup'
            ],
        ],
        'image' => 'anomaly.field_type.file',
    ];

    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'products',
        'sortable' => true,
    ];
    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
        'image',
        'link',
        'title',
        'description',
    ]; ?> ```

I created a new migration with:
``` <?php
public function up()
    {
$stream = $this->streams()->findBySlugAndNamespace('products', 'profront_products_block');

        $stream
            ->setAttribute('translatable', true)
            ->save();
        $assignments = $this->assignments()->findByStream($stream);

        foreach($assignments as $assignment){
            $assignment
                ->setAttribute('translatable', true)
                ->save();
        } ?>

When I run that it makes the stream translatable but it doesnt create the ProfrontProductsBlockProductsEntryTranslationsModel file in the storage. When I manually run streams:compile it does make that, but it doesn't make the database table for it (default_profront_products_block_blocks_products_translations)

What is going wrong here??

ryanthompson  —  6 years ago

Something I noticed in the control panel - the UI disabled making streams translatable after the fact and the code is doc'd saying this too.

We don't have a good way to move a column AND it's data to another table so the translatable flag MUST be set at creation. Time to migrate:reset perhaps. If you know of any good packages or ways of tackling this I would be happy to build it in!

william  —  6 years ago

So at the moment, if you have built a pretty big site in one language, and then you wanna add another language to the site. We are not able to do it?

At that point, rolling back and migrating is not really an option because of all the data. What would you recommend doing @ryanthompson ? Even if it's some manual work, kind of interesting to know since i might be in the situation down the road.

ryanthompson  —  6 years ago

You can add another language.. if you marked streams translatable. Things that are NOT translatable can't easily be made translatable because of the potentially moving data all over the place. That's why it's important to keep this in mind when you are building :-/

Imagine you have an image file that needs to be made all of a sudden translatable.. we have to make the new column on the translations table (including any rename or other edits made), then we need to move all the data to the new column on the translations table, then clean up the old columns.

It's kinda a chore which is why it's disabled in the CP.

ryanthompson  —  6 years ago

You could write a few migrations to do this yourself though. Make the table (see core code) and move the data yourself.

william  —  5 years ago

I guess whenever creating blocks extensions, we should always mark them translatable as well? To make sure we don't run into these issues later? Or has this been sorted since this discussion?

ryanthompson  —  5 years ago

You sure could - we specifically don't because we rarely make translatable sites though.