Skip to content

Commit 7d4dd2c

Browse files
Benedikt ArteltMrSerth
andcommitted
Add multilingual support for exercise descriptions
Closes #2743 Merges #2928 Co-authored-by: Sebastian Serth <[email protected]>
1 parent 9374bce commit 7d4dd2c

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed

app/javascript/multilang_de.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:root[lang="de"] .multilang:not([lang="de"]) {
2+
display: none;
3+
}

app/javascript/multilang_en.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:root[lang="en"] .multilang:not([lang="en"]) {
2+
display: none;
3+
}

app/views/exercises/_form.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Force a full page reload, see https://github.com/turbolinks/turbolinks/issues/326.
33
Otherwise, code might not be highlighted correctly (race condition)
44
meta name='turbolinks-visit-control' content='reload'
5+
- append_stylesheet_pack_tag("multilang_#{I18n.locale}")
56
- append_javascript_pack_tag('sortable')
67
- append_javascript_pack_tag('toast-ui')
78
- append_stylesheet_pack_tag('toast-ui')

app/views/exercises/_tips_content.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
meta name='turbolinks-visit-control' content='reload'
55
- append_javascript_pack_tag('highlight')
66
- append_stylesheet_pack_tag('highlight')
7+
- append_stylesheet_pack_tag("multilang_#{I18n.locale}")
78

89
#tips.card.d-block.overflow-scroll role='tab'
910
.card-header.py-2

app/views/exercises/implement.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Force a full page reload, see https://github.com/turbolinks/turbolinks/issues/326.
33
Otherwise, lti_parameters might be nil
44
meta name='turbolinks-cache-control' content='no-cache'
5+
- append_stylesheet_pack_tag("multilang_#{I18n.locale}")
56

67
#editor-column
78
- unless @embed_options[:hide_exercise_description]

app/views/tips/_form.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Force a full page reload, see https://github.com/turbolinks/turbolinks/issues/326.
33
Otherwise, code might not be highlighted correctly (race condition)
44
meta name='turbolinks-visit-control' content='reload'
5+
- append_stylesheet_pack_tag("multilang_#{I18n.locale}")
56
- append_javascript_pack_tag('toast-ui')
67
- append_stylesheet_pack_tag('toast-ui')
78

app/views/tips/show.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
meta name='turbolinks-visit-control' content='reload'
55
- append_javascript_pack_tag('highlight')
66
- append_stylesheet_pack_tag('highlight')
7+
- append_stylesheet_pack_tag("multilang_#{I18n.locale}")
78

89
h1
910
= @tip.to_s

docs/multilang.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Multilanguage Support for Exercises and Tips
2+
3+
This document provides an overview of how to support multilingual exercise descriptions and tips that are displayed in the exercise implementation view.
4+
5+
## Introduction
6+
7+
To improve the maintenance of exercises in multilingual teaching scenarios, it may be better to provide exercises with exercise descriptions in several languages than to work with translated copies of an exercise. CodeOcean already has multilingual support that can be used to achieve this.
8+
9+
The implementation of multilanguage support in CodeOcean is inspired by [Moodle's Multilang Content Filter](https://docs.moodle.org/405/en/Multi-language_content_filter): Attributes are used to indicate the multilingual nature of a content element (`class="multilang"`) and to specify the exact language (`lang="XX"`). CSS is then used to control the visibility on the page.
10+
11+
## Usage
12+
13+
When making exercise descriptions or tips multilingual, the `.multilang` class must be assigned to all multilingual content. The `lang` attribute must be set to the appropriate locale, e. g., `"en"` or `"de"`. This very simple solution can be applied in many different ways:
14+
15+
Example 1 (Separated Multilingual Content Blocks):
16+
17+
```html
18+
<p class="multilang" lang="de">Implementieren Sie eine Funktion, die für einen gegebenen Parameter entscheidet, ob er gerade oder ungerade ist.</p>
19+
<p class="multilang" lang="en">Implement a function that decides for a given parameter whether it is even or odd.</p>
20+
```
21+
22+
Example 2 (Inline Separation of Multilingual Content):
23+
24+
```html
25+
<p><span class="multilang" lang="de">Implementieren Sie eine Funktion, die für einen gegebenen Parameter entscheidet, ob er gerade oder ungerade ist.</span><span class="multilang" lang="en">Implement a function that decides for a given parameter whether it is even or odd.</span></p>
26+
```
27+
28+
This approach also applies to the description of tips, including their example sections.
29+
30+
## Supported Locales
31+
32+
At the time of writing CodeOcean supports the `DE` and `EN` locales. Accordingly, the two CSS snippets [`multilang_de.scss`](../app/javascript/multilang_de.scss) and [`multilang_en.scss`](../app/javascript/multilang_en.scss) have been added to the application. To support other locales, just copy and paste one of these snippets and change the locale in the CSS rule. To really take effect, the appropriate locale must be added to CodeOcean (see [Config --> Locales](../config/locales/) for details) and also requires a change to `Rails.application.config.i18n.available_locales` in [`config/application.rb`](../config/application.rb).

0 commit comments

Comments
 (0)