Exercise widgets
Five web components for interactive, vocabulary, word game, pronunciation and verb exercises.
Besides conversations, Linguineo offers interactive exercises, vocabulary and verb trainers, word games and pronunciation exercises. They all come from one library, with one custom element per exercise family. All elements share the same attributes, events and result format.
Elements#
| Element | Exercise family |
|---|---|
linguineo-multimedia-exercise | Interactive exercises around text, images, audio and video, such as multiple choice, gap fill, drag and drop, matching and open speaking or writing tasks. |
linguineo-vocabulary-exercise | Vocabulary trainer: learn and practice new words in short sessions. |
linguineo-wordgame-exercise | Word games to practice vocabulary in a playful way. |
linguineo-pronunciation-exercise | Pronunciation exercises: listen to a model, record yourself and get feedback down to the individual sound. |
linguineo-verbs-exercise | Verb trainer: practice conjugations. |
Use the element that matches the type of the exercise you load. If you build a generic exercise page, choose the element based on the exercise type in the exercise definition.
Load the library#
<script type="module" src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es2015.js"></script>
<script nomodule src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es5.js"></script>One library registers all five elements.
The exercise definition#
Unlike the conversation player, which loads a scenario by its ID, an exercise widget receives the complete exercise definition as a JSON string in the exercise attribute. You usually get this JSON from the Linguineo content creation API. Fetch it in your back end and pass it on unchanged.
Pass the definition exactly as you received it, as a string. The widget parses it itself (JSON.parse), so passing an object or a modified copy will not work.
Quick start#
<linguineo-vocabulary-exercise
id="exercise"
language="fr"
tutor-language="nl"
auth-method="bearer"
></linguineo-vocabulary-exercise>
<script type="module" src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es2015.js"></script>
<script nomodule src="https://cdn.linguineo.com/linguineo-exercises/1.1.0/exercises-webcomponents-es5.js"></script>
<script>
const el = document.getElementById('exercise');
// the exercise definition (JSON string), loaded through your own back end
fetch('/my-backend/exercises/123')
.then((res) => res.text())
.then((exerciseJson) => {
el.setAttribute('access-token', getAccessToken()); // token of the signed-in learner
el.setAttribute('exercise', exerciseJson);
});
el.addEventListener('linguineo:end', (event) => {
console.log('Exercise finished', event.detail);
});
</script>Attributes#
All five elements accept these attributes. The camelCase name below each attribute is the property to use from JavaScript or a framework.
| Attribute | Type | Default | Description |
|---|---|---|---|
exercisereqexercise | JSON string | The complete exercise definition. See The exercise definition. | |
access-tokenreqaccessToken | string | Access token of the learner. See Authentication. | |
auth-methodauthMethod | enum | default | bearer, default or none. Use bearer with a token from your own identity provider. |
user-iduserId | string | Linguineo user ID. Only needed with default authentication. | |
usernameusername | string | User name that goes with user-id. Only needed with default authentication. | |
languagelanguage | string | nl | ISO 639-1 code of the language the learner practices. |
tutor-languagetutorLanguage | string | nl | ISO 639-1 code of the language for instructions and translations. |
applicationapplication | string | App identifier. Only set this if Linguineo gave you one. | |
language-levellanguageLevel | string | CEFR level of the learner: A1, A2, B1, B2, C1 or C2. | |
with-back-buttonwithBackButton | boolean | false | Show a back button. Pressing it fires linguineo:back. |
header-with-simple-backgroundheaderWithSimpleBackground | boolean | true | Use a plain background for the exercise header. |
auditive-playback-activeauditivePlaybackActive | boolean | true | Play audio (such as the pronunciation of words) automatically. |
auditive-playback-with-iconauditivePlaybackWithIcon | boolean | false | Show a speaker icon to play audio. |
automatic-content-translations-enabledautomaticContentTranslationsEnabled | boolean | true | Show automatic translations of the content in the tutor language. |
sound-effects-enabledsoundEffectsEnabled | boolean | true | Enable interface sound effects. |
stop-recording-on-silencestopRecordingOnSilence | boolean | true | Pronunciation and verb exercises only: stop recording automatically when the learner stops speaking. |
exercise-styling-classexerciseStylingClass | string | CSS class for the main color scheme of the exercise. | |
alternate-styling-classalternateStylingClass | string | CSS class for the alternate color scheme. | |
connection-configconnectionConfig | JSON string | Linguineo APIs | Custom API endpoints. See Connection settings. |
Events and results#
The exercise widgets fire the same events as the conversation player:
| Event | Fired when | event.detail |
|---|---|---|
linguineo:end | The learner finishes the exercise. | The result object. |
linguineo:back | The learner presses the back button. | Nothing. |
The result contains the shared fields (percentage, pointsAwarded, needsManualEvaluation, durationInMs, purpose, exerciseSessionId) plus details for the exercise family, such as the answers per question, word or sentence. See Events and results for the shared fields. To read the result before the learner finishes, use element.currentExerciseResult.
Angular#
Add CUSTOM_ELEMENTS_SCHEMA to your module or standalone component and bind the inputs as properties:
<linguineo-vocabulary-exercise
[exercise]="exerciseAsJson"
[language]="exercise.language"
[tutorLanguage]="tutorLanguage"
[withBackButton]="false"
[soundEffectsEnabled]="true"
[accessToken]="user?.accessToken"
[authMethod]="'bearer'"
></linguineo-vocabulary-exercise>The event name contains a colon, so listen for it with a host listener instead of an (event) binding in the template:
@HostListener('window:linguineo:end', ['$event'])
onExerciseFinished(event: CustomEvent) {
this.saveResult(event.detail);
}React#
Pass values as attributes and attach event listeners through a ref:
import { useEffect, useRef } from 'react';
export function VocabularyExercise({ exerciseJson, accessToken, onEnd }) {
const ref = useRef(null);
useEffect(() => {
const el = ref.current;
const handleEnd = (event) => onEnd(event.detail);
el.addEventListener('linguineo:end', handleEnd);
return () => el.removeEventListener('linguineo:end', handleEnd);
}, [onEnd]);
return (
<linguineo-vocabulary-exercise
ref={ref}
exercise={exerciseJson}
language="fr"
tutor-language="nl"
auth-method="bearer"
access-token={accessToken}
/>
);
}