Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC/WIP] ability to see original content from translated attributes #4262

Closed
wants to merge 4 commits into from

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Mar 11, 2022

WHY

BEFORE - What was wrong? What was happening before this PR?

As reported in #4100 our translatable fields have a stange behaviour.

  • You create an entry in the app language (en), then you go edit the French language. You will see that the en value is there pre-populated. You could think: ok, nice, it kinda helps to know the english value for translation, but it's something you don't want translated in that language, so you just clear the field, and submit the form.

If you go to the database, you will see that you have both keys en/frand that en has value and fr is null, as is expected.

But if you open that same entry to edit in fr again, you will see that the same en value is populated. If you notice you can just delete it again and save, but if it's in other tab and you hit save without checking that you will have the fr translation with the en translation.

AFTER - What is happening after this PR?

This PR aims to provide a away to don't pre-populate un-translated fields, but easy enough to get the translations.

HOW

How did you achieve that, in technical terms?

  • First set the Model locale when getting the entry in Read trait.
  • refactored the "backpack getTranslation", to keep the default behaviour for people using the same model outside the backpack panel, because the default getTranslation will assume that empty, null or not present is the same as not beeing translated, so it get the value through the fallbacks.
  • created a easy way to get the original value.

Is it a breaking change or non-breaking change?

I think it is, not that I think the previous behaviour was ok, so this can also be seen as a fix.

How can we test the before & after?

Use the simple example I gave, it's very easy to spot this problem.

Disregard completely any code refactoring / functionality etc. This is a POC for us to discuss if we should aim for a solution like this.

@pxpm pxpm added this to In Progress in 🚀 Backpack v5 (Launch) via automation Mar 11, 2022
@pxpm pxpm added the Minor Bug A bug that happens only in a very niche or specific use case. label Mar 11, 2022
@pxpm pxpm closed this Mar 15, 2022
🚀 Backpack v5 (Launch) automation moved this from WIP to Done Mar 15, 2022
@pxpm pxpm deleted the translatable branch March 15, 2022 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A bug that happens only in a very niche or specific use case.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants