This PR adds the ExperimentTranslatedContent model to the application, along with its related functionality. It has the following properties:
Model
experiment - FK to the Experiment model
language - The language code for the content's language
index - Sorting property, the content with the lowest index will be considered the fallback language/content (for now)
title - This was originally the Experiment's title
description - This was originally the Experiment's description
consent - This was originally the Experiment's consent
about_content - This was originally the Experiment's about_content
The PR also adds some helper methods to the Experiment model, get_fallback_content and get_translated_content. These are used to get the appropriate content for the given context.
The languages of the configured ExperimentTranslatedContents for an Experiment determine the possible languages in which an experiment can be used. These languages will also determine the languages used at the SocialMediaConfig, ThemeConfig, and Block 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 the get_language helper function to determine the user's preferred language. This language is used to find the appropriate ExperimentTranslatedContent. If it cannot find it, it will take the experiment's translated content with the lowest index number. If that doesn't exist either, it will throw an error as an Experiment 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 the active language for the whole experiment, its related entities, and the non-experiment related content using Django activate(language) function (which was used earlier at the Block level depending on the configured language there.
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.
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.https://github.com/Amsterdam-Music-Lab/MUSCLE/blob/5d90e4b27b777530ad5ad19d6a0fe166fd25550e/backend/experiment/models.py#L68-L87
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.https://github.com/Amsterdam-Music-Lab/MUSCLE/blob/066b9381fd64d57a502b5516a93212f207cd9916/backend/experiment/views.py#L128-L136
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