Voyager: Rich Text & Translatable, field cannot be saved

Created on 13 Oct 2017  路  19Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.5.14
  • Voyager Version: 1.0.5
  • PHP Version: 7.0.24
  • Database Driver & Version: MariaDB 5.5.53

Description:

Hello Everybody,
i tried to search on closed issue without luck.
I found a bug on system.
When i use rich text on BREAD and i have Translatable Trait on model the field cannot be saved.
If i deactivate Translation everything is ok.
The same way if i use a text or textarea field and Translations.

This is a schematic version for easy comprehension:
Rich Text & Translatable = no save field
Not Rich Text & Translatable = save field
Rich Text & Not Translatable = save field

Can anybody find a way to solve this?
thank you very much
Alex

possible bug

Most helpful comment

No one have the same issue?

All 19 comments

No one have the same issue?

I just tested it with the --with-dummy flag at installation of voyager... It works pretty nice(maybe missing an alert or something when switching between languages, so we know if it was changed correctly)
Maybe you are missing to change at config/voyager.php the multilingual => enabled key to true

Hi Triztan,
this is my config/voyager.php section:
'multilingual' => [ 'enabled' => true, 'default' => 'it', 'locales' => [ 'it', 'en', ], ],
on my models i put use TCG\Voyager\Traits\Translatable; and use Translatable; into class.
I also set protected $translatable = ['testo', 'orari']; to set what fields need to be translated.

I forgot something?

Thank you very much
Alex

Nobody?

I think the problem is here in src/Helpers/helperTranslations.php:
The stripHTMLTags comes in as true and it strips the html. With this way the values are saves in database but there is no proper html to be shown. This happens when multilingual is enabled.

function get_field_translations($model, $field, $rowType = '', $stripHtmlTags = false)
    {
        $_out = $model->getTranslationsOf($field);

        if ($stripHtmlTags && $rowType == 'rich_text_box') {
            foreach ($_out as $language => $value) {
                $_out[$language] = strip_tags($_out[$language]);
            }
        }

        return json_encode($_out);
    }

as a comment to this: if you look into the database, all the tags are there, tinymce just won't display them.

In my case, into the database these fields are empty

@bedoz look at it #2303

I have the same issue. Post body's hidden translation field has only one language in stored json data and the ui doesn't change. On submission i get undefined index 'en' exception.

@neutronstein Thats unrelated to the original issue and has been fixed in https://github.com/the-control-group/voyager/pull/3265 (which will be released with 1.1.3)

  • Laravel Version: 5.5.40
  • Voyager Version: 1.1
  • PHP Version: 7.0.8

@bedoz
I had Absolute Same issue...

No FIX From unset() destroyes fields

No FIX From div class="panel-body" removal

Steps To Reproduce:

. Enable Support for Multilingual
config/voyager.php

Set to True
'multilingual' => [
'enabled' => true,

Add Extra Languages

 'locales' => [
    'en',
    'ru',
    'ge',
 ],

.Let's take for Example Model Posts
As you said, Model Must be Translatable

.Copy/Paste A Model Post From:

vendor/tcg/voyager/src/Models/

TO

App/ModelName

.Set Namespace

. Go To http://yourappname/admin/bread/posts/edit

Change (Reference)
_Model Name_
TO
_App/ModelName_

. Now you can Set which Fields to Be TRANSLATED: ex: protected $translatable = ['title','body'];
. Warning! There is a Bug For Posts View Which is Updated Issued on #3265

. Paste that edit-add.blade.php IN resources\views\vendor\voyager\posts\

And it Works Finally ))

Sum Up

  • Translation Worked on Model Post
  • Translation Worked on Model Page (Without Extra View)
  • Translation Worked on Menu

. Somehow Fixed My Problem...
. Almost Left To Use Voyager Translator System

Hope this Helps to Someone

@Madhackers21, you've simply followed the correct procedure. One change I would recommend, however. Instead of copying the model in its entirety, I would create a new model and extend the other one. This should help reduce issues when upgrading.

@fletch3555

Exactly...
You're correct: Must use
php artisan make:model Modelname

Can't save multilanguage images!
'Undefined index "ru"'

but can save image with not default translation - 'en'. When I'm switching to default language (whitch is 'ru'), I see the same image from 'en' locale although the field must be empty.

Here is my request:
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="_method"

PUT
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="_token"

J4sZ9S1juECQaIE8X5oh0QnteTdcG7FcD9KBsKhB
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="name_i18n"

{"ru":"Velit odio saepe.","en":"Velit odio saepe."}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="name"

Velit odio saepe.
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="code_i18n"

{"ru":"sint-ab-dolorem","en":"sint-ab-dolorem"}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="code"

sint-ab-dolorem
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="active"

on
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="active_date"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="sort"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="content_restriction"

no
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="keywords_i18n"

{"ru":"","en":""}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="keywords"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="release_id"

50
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="UDC"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="price"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="image_i18n"

{"en":""}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="image"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="description_i18n"

{"ru":"邪褌邪褌邪 薪邪褏褍泄","en":"description in english"}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="description"

邪褌邪褌邪 薪邪褏褍泄
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="preview_image_i18n"

{"en":""}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="preview_image"; filename=""
Content-Type: application/octet-stream

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="preview_description_i18n"

{"ru":"","en":""}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="preview_description"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="bibliography_i18n"

{"ru":"","en":""}
------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="bibliography"

------WebKitFormBoundarynWAiNge9Wmpm3gcg
Content-Disposition: form-data; name="created_at"

11/27/2018 8:38 AM
------WebKitFormBoundarynWAiNge9Wmpm3gcg--

As you can see, all fields send smth like {"ru":"","en":""}, but only images send {"en":""}

May be it should be opened a new issue?
How can I solve this problem?
How to work with multilanguage images?

Files and images are not "translatable", so that looks unrelated.

Files and images are not "translatable", so that looks unrelated.

May be it would be done at next release of the Voyager?

I have to ask again because I seem to have the exact same problem.

I have a model 'Ticket' with the Translatable Trait where 'title' is a simple text field and 'abstract' a rich text box.

When I try to save, I get the error 'Undefined index: en' and the post-data of the request looks like this:

_method | "PUT"
_token | "ftLqdr61PDpPctMoCOatNLQGFCFkVLHkiRkH2009"
title_i18n | "{"en":"title text"}"
title | "title text"
abstract_i18n | "{}"
abstract | "< p >rich text< /p >"
doors | "04/10/2019 9:18 AM"
start | "04/10/2019 9:18 AM"
ticket_group_id | "1"

The translated field of the rich-text-box is empty, which causes the error in the Translatable Trait.

Any guesses? Thanks in advance

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raoasifraza1 picture raoasifraza1  路  3Comments

duongsieu picture duongsieu  路  3Comments

IvanBohonosiuk picture IvanBohonosiuk  路  4Comments

winex01 picture winex01  路  3Comments

wislem picture wislem  路  3Comments