question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] translatable model not showing correct language translations in edit form

See original GitHub issue

Bug report

What I did

Tried to use HasTranslations trait on my MenuItem model in order to be able to use translations for that model

What I expected to happen

To be able to translate my models in different languages

What happened

Every language edit form shows same current values (of default language). Save operation works - for example, I can change values and it shows different in in database, but backpack edit form still shows values from default language for every language.

What I’ve already tried to fix it

Tried to override/extend these methods: vendor/backpack/crud/src/app/Http/Controllers/Operations/UpdateOperation.php -> edit vendor/backpack/crud/src/app/Library/CrudPanel/Traits/Update.php -> getModelAttributeValue But the final result gets ugly and/or with a lot of repetitive code. I believe the issue is 80 line of Update.php -> getModelAttributeValue:

return $model->{$field['name']};

it takes default value of the model (default locale) whereas instead it should take translated value for corresponding locale that’s in request (_locale)

quick fix in UpdateOperation.php -> edit:

app()->setLocale(request()->input('_locale') ?? app()->getLocale());
$this->crud->setOperationSetting('fields', $this->crud->getUpdateFields());
app()->setLocale(config('app.locale'));

Is it a bug in the latest version of Backpack? - yes

After I run composer update backpack/crud the bug… is it still there? - yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

### PHP VERSION:
PHP 8.0.6 (cli) (built: May  4 2021 23:31:45) ( ZTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.6, Copyright (c) Zend Technologies

### LARAVEL VERSION:
v9.9.0@4d5a07640891b772188d7737348886a0222737d8

### BACKPACK VERSION:
5.0.14@1e355c4c046a34423a1a3e3150120245a4bfd8e9

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, May 26, 2022

Oh, got it! Meant to tag @kartomantas then sorry. In any case…

We’ve just merged https://github.com/Laravel-Backpack/CRUD/pull/4399 and tagged 5.0.19 which fixes this issue. Please run composer update backpack/crud to get 5.0.19 or higher, and this should be fixed! 🎉 If it’s not, please reply here to let us know, and we’ll reopen.

Sorry again this took so long to fix. We mistakenly thought this was about a more minor problem.

Cheers!

1reaction
guleswinecommented, May 26, 2022

@tabacitu hi this is not my topic, I closed (https://github.com/Laravel-Backpack/CRUD/issues/4326) mine when I saw the fix from @pxpm https://github.com/Laravel-Backpack/CRUD/pull/4267

and I’m already using two of his PRs (very important to me), so it’s still hard for me to update to new versions 😀(second https://github.com/Laravel-Backpack/CRUD/pull/4359)

but yes, in the current topic the problem is that the language does not change

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make Your Forms Multilingual - Jotform
Right below the Form Language section, click the Edit button next to Translations. Click the Add form language button next.
Read more >
Translations in Analysis Services tabular models
Click Extensions > Model > Translations > Manage Translations. Select the languages for which you are providing translations and then click Add.
Read more >
Common Errors with Exporting and Importing Translation Files
This error message only applies to data translation files. Data translation isn't enabled or was disabled after the data translation file was exported....
Read more >
Error messages in Dynamic Translation
Error messages on forms and activity streams · Credentials configured for the translation service provider under the Connections & Credentials ...
Read more >
Hint NOT Working in Formbuilder for multiple languages ...
Workaround is to download XSL and change column name to guidance_hint::language (dafault), than re-import. ... From know on all works fine: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found