Running an experiment in several languages #1868
-
Hello! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @yseulthb, great question. You can do this using dynamic parameters so that you only need to create the instruction trial once (and any other trial that includes text), and make any text-related parameters dynamic, i.e. functions that return the appropriate value, based on the language that was selected. There are lots of ways to do this, but here's one example. In this example I've created a global variable called (Apologies to all Spanish speakers for errors!) // create a global variable to hold the language selection
var lang = null;
var preferred_language = {
type: 'survey-multi-choice',
questions: [{
prompt: '<p>What is your preferred language? /</p>¿Cual es tu idioma preferido?',
options: ['English/Inglés','Spanish/Español'],
name: 'lang',
required: true
}],
on_finish: function(data) {
// set the value of the lang variable based on the participant's choice
if (data.response.lang == "English/Inglés") {
lang = "eng";
} else {
lang = "spa";
}
}
};
var instructions = {
type: 'instructions',
pages: function() {
// use a dynamic parameter to use different instruction text strings, depending on the current value of the lang variable
if (lang == "eng") {
return ['Welcome!', 'In this experiment...']
} else if (lang == "spa") {
return ['¡Bienvenido!', 'En este experimento...']
}
},
show_clickable_nav: true,
button_label_next: function() {
// use a dynamic parameter to use different button labels, depending on the current value of the lang variable
if (lang == "eng") {
return "Next";
} else if (lang == "spa") {
return "Próximo";
}
},
button_label_previous: function() {
if (lang == "eng") {
return "Back";
} else if (lang == "spa") {
return "Atrás";
}
}
};
jsPsych.init({
timeline: [preferred_language, instructions],
on_finish: function(){jsPsych.data.displayData();}
}); |
Beta Was this translation helpful? Give feedback.
Hi @yseulthb, great question. You can do this using dynamic parameters so that you only need to create the instruction trial once (and any other trial that includes text), and make any text-related parameters dynamic, i.e. functions that return the appropriate value, based on the language that was selected.
There are lots of ways to do this, but here's one example. In this example I've created a global variable called
lang
. The value isnull
when the experiment starts, and then it's set in theon_finish
function of the trial where the participant selects their preferred language. This way, thelang
variable can be used throughout the whole experiment to determine what text-related paramet…