-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added: Add translated_content model and update Experiment model #1208
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The commit removes the `name`, `description`, `consent`, and `about_content` fields from the `Experiment` model and updates the admin forms accordingly.
This commit adds a `fallback` parameter to the `get_translated_content` method in the `Experiment` model. When set to `True`, if no content is found for the specified language, it will return the primary content instead. If `fallback` is set to `False` and no content is found, a `ValueError` will be raised. Refactor the `get_content` method to `get_translated_content` to better reflect its purpose.
…iew as this has been replaced at the experiment level per #1204
…Accept-Language` header's value
BeritJanssen
reviewed
Aug 5, 2024
backend/experiment/migrations/0050_migrate_experiment_content_to_translatedmakemigrations.py
Outdated
Show resolved
Hide resolved
BeritJanssen
approved these changes
Aug 5, 2024
This commit modifies the migration file `0050_migrate_experiment_content_to_translatedmakemigrations.py` to delete all experiment translated content using the `ExperimentTranslatedContent.objects.all().delete()` method. This change is necessary to clean up the database and ensure that no translated content exists anymore after running the reverse migration.
drikusroor
force-pushed
the
feat/translated-content
branch
from
August 5, 2024 07:45
7c5c34c
to
90fd4ac
Compare
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the
ExperimentTranslatedContent
model to the application, along with its related functionality. It has the following properties:Model
experiment
- FK to theExperiment
modellanguage
- The language code for the content's languageindex
- Sorting property, the content with the lowest index will be considered the fallback language/content (for now)title
- This was originally the Experiment's titledescription
- This was originally the Experiment's descriptionconsent
- This was originally the Experiment's consentabout_content
- This was originally the Experiment's about_contentThe PR also adds some helper methods to the
Experiment
model,get_fallback_content
andget_translated_content
. These are used to get the appropriate content for the given context.MUSCLE/backend/experiment/models.py
Lines 68 to 87 in 5d90e4b
Serialisation & active language handling
The languages of the configured
ExperimentTranslatedContent
s for anExperiment
determine the possible languages in which an experiment can be used. These languages will also determine the languages used at theSocialMediaConfig
,ThemeConfig
, andBlock
level. Right now, what happens is that the user has a preferred language that is used to get the appropriate content and fall back to the experiment's fallback language if it is not available. Django has theget_language
helper function to determine the user's preferred language. This language is used to find the appropriateExperimentTranslatedContent
. If it cannot find it, it will take the experiment's translated content with the lowestindex
number. If that doesn't exist either, it will throw an error as anExperiment
needs a content in order to work. (We might want to require at least one translated content per experiment during creation and updating.)The language of the
ExperimentTranslatedContent
(preferred or fallback) will be used as theactive
language for the whole experiment, its related entities, and the non-experiment related content using Djangoactivate(language)
function (which was used earlier at theBlock
level depending on the configured language there.MUSCLE/backend/experiment/views.py
Lines 128 to 136 in 066b938
Consent
The retrieval of the consent form works slightly different. If a consent form cannot be found in the preferred language, but does exist at the fallback level, the consent form from the fallback language will be used. This gives the user flexibility in configuring consent form: Configure consent forms in all languages, configure consent forms in only one or a limited selection of the experiment languages, or configure no consent forms at all.
Things to do after merging this PR
The migrations copy the Experiment's content to a newly created ExperimentLanguageContent, with the language set to English. This means that we have to go over all experiments after the migration and set the language to Dutch or Chinese if that's the Experiment's original language.
Related to #1204