Skip to content

Commit

Permalink
Frontend: filter displayed questions & quizs depending on locale. ref #…
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 23, 2021
1 parent 1eaf4fa commit f0222be
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 54 deletions.
10 changes: 9 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,28 @@ export default {
},
},
watch: {
// eslint-disable-next-line
'$i18n.locale' (newLocale, oldLocale) {
// reload data (includes updating locale in the store)
this.initData();
},
},
mounted() {
// set locale
if (Object.keys(this.$route.query).length) {
if (Object.keys(this.$route.query).includes('locale')) {
this.$i18n.locale = this.$route.query.locale || process.env.VUE_APP_I18N_LOCALE;
}
}
// load data
this.initData();
},
methods: {
initData() {
this.$store.dispatch('SET_LOCALE');
this.$store.dispatch('GET_CONFIGURATION_DICT_FROM_LOCAL_YAML');
this.$store.dispatch('GET_DIFFICULTY_LEVEL_LIST_FROM_LOCAL_YAML');
this.$store.dispatch('GET_AUTHOR_LIST_FROM_LOCAL_YAML');
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<div class="col-sm">
<select v-model="$i18n.locale">
<option v-for="(lang, i) in languages" :key="`Lang${i}`" :value="lang.key">
{{ lang.value }}
{{ lang.emoji }}&nbsp;{{ lang.value }}
</option>
</select>
</div>
Expand All @@ -68,6 +68,7 @@
</template>

<script>
import constants from '../constants';
import HomeLink from './HomeLink.vue';
export default {
Expand All @@ -80,10 +81,7 @@ export default {
data() {
return {
languages: [
{ key: 'fr', value: '🇫🇷 Français' },
{ key: 'en', value: '🌐 English' },
],
languages: constants.LANGUAGE_CHOICE_LIST,
};
},
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/QuestionAnswerCards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<h2 v-if="questionAnswer.success">{{ questionAnswer.message }} !</h2>
<h2 v-if="!questionAnswer.success">{{ questionAnswer.message }}</h2>
<h3 v-if="!questionAnswer.success">
<small>{{ $t('messages.answerWas') }}&nbsp;</small>
<small>{{ $t('messages.answerWas') }}{{ $t('words.semiColon') }}&nbsp;</small>
<span>{{ question["answer_option_" + question["answer_correct"]] }}</span>
</h3>
<!-- Answer explanation -->
Expand Down Expand Up @@ -110,7 +110,7 @@
<img v-bind:src="question.answer_image_url" alt="une image pour illustrer la réponse" />
</a>
</p>
<p v-if="question.answer_image_explanation" class="answer-image-explanation" title="Légende de l'image">{{ $t('messages.imageLegend') }} {{ question.answer_image_explanation }}</p>
<p v-if="question.answer_image_explanation" class="answer-image-explanation" title="Légende de l'image">{{ $t('messages.imageLegend') }}{{ $t('words.semiColon') }} {{ question.answer_image_explanation }}</p>
</div>

<div v-if="question && questionSubmitted && questionNotValidated" class="alert alert-warning">
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/QuizCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default {
},
watch: {
// eslint-disable-next-line
},
mounted() {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ export default {
QUIZ_RELATIONSHIP_SIMILAR: 'similaire',
QUIZ_RELATIONSHIP_TWIN: 'jumeau',
QUIZ_RELATONSHIP_TRANSLATION: 'traduction',
LANGUAGE_CHOICE_LIST: [
{ key: 'fr', value: 'Français', emoji: '🇫🇷' },
{ key: 'en', value: 'English', emoji: '🌐' },
],
// DEFAULT_BACKGROUND_IMAGE_NAME: 'https://quizanthropocene.fr/showyourstripes_globe_1850-2019.png'
};
4 changes: 3 additions & 1 deletion frontend/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function loadLocaleMessages() {
return messages;
}

export default new VueI18n({
const i18n = new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages(),
});

export default i18n;
10 changes: 7 additions & 3 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"item1Subtitle": "(we do our best :)",
"item2Title": "Explore and filter with the <span class='text-secondary'>categories</span> & <span class='color-tag'>tags</span>",
"item3Title": "Attentive to feedback",
"item3Subtitle": "and open to "
"item3Subtitle": "and open to",
"thereIsCurrently": "There are currently",
"helpUs": "Help us",
"toAddMore": "to add more"
},
"footer": {
"home": "Home",
Expand Down Expand Up @@ -58,14 +61,15 @@
"multipleAnswers": "multiple answers possible",
"hint": "Hint",
"submit": "Submit",
"answerWas": "The answer was:",
"imageLegend": "Legend:",
"answerWas": "The answer was",
"imageLegend": "Legend",
"questionPendingValidation": "This question is pending validation",
"thanks": "Thanks",
"thankYou": "Thank You",
"errorOccured": "An error occured"
},
"words": {
"et": "and",
"times": "times",
"cette": "this",
"ce": "this",
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"item1Subtitle": "(on fait de notre mieux :)",
"item2Title": "Explorer et filtrer grâce aux <span class='text-secondary'>catégories</span> & <span class='color-tag'>tags</span>",
"item3Title": "À l'écoute de vos retours",
"item3Subtitle": "et ouvert aux "
"item3Subtitle": "et ouvert aux ",
"thereIsCurrently": "Il y a actuellement",
"helpUs": "Aidez-nous",
"toAddMore": "à en rajouter plus"
},
"newsletter": {
"success": "Votre inscription à la newsletter a été enregistrée, merci !"
Expand Down Expand Up @@ -61,14 +64,15 @@
"multipleAnswers": "plusieurs réponses possibles",
"hint": "un indice",
"submit": "Valider",
"answerWas": "La réponse était :",
"imageLegend": "Légende :",
"answerWas": "La réponse était",
"imageLegend": "Légende",
"questionPendingValidation": "Cette question est en cours de validation",
"thanks": "Merci",
"thankYou": "Merci beaucoup",
"errorOccured": "Il y a eu une erreur"
},
"words": {
"et": "et",
"times": "times",
"cette": "cette",
"ce": "ce",
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue';
import Vuex from 'vuex';

import i18n from './i18n';
import constants from './constants';

// webpack + vue-cli-plugin-yaml
Expand Down Expand Up @@ -29,6 +30,7 @@ const store = new Vuex.Store({
loading: false,
error: null,
configuration: {},
locale: {},
questions: [],
questionsValidated: [],
questionsDisplayed: [],
Expand Down Expand Up @@ -64,6 +66,13 @@ const store = new Vuex.Store({
commit('UPDATE_LOADING_STATUS', false);
commit('UPDATE_ERROR', null);
},
/**
* Set app locale
*/
SET_LOCALE: ({ commit }) => {
const localeDict = constants.LANGUAGE_CHOICE_LIST.find((l) => l.key === i18n.locale);
commit('SET_LOCALE_DICT', { dict: localeDict });
},
/**
* Get app configuration
*/
Expand All @@ -77,8 +86,7 @@ const store = new Vuex.Store({
* - enrich with categories, tags
*/
GET_QUESTION_LIST_FROM_LOCAL_YAML: ({ commit, state, getters }) => {
// questions
const questions = questionsYamlData;
const questions = questionsYamlData.filter((q) => q.language === state.locale.value);
// questions: get category & tags objects
questions.map((q) => {
const questionCategory = getters.getCategoryById(q.category);
Expand Down Expand Up @@ -111,7 +119,7 @@ const store = new Vuex.Store({
* - enrich with questions, tags
*/
GET_QUIZ_LIST_FROM_LOCAL_YAML: ({ commit, state, getters }) => {
const quizzes = quizzesYamlData;
const quizzes = quizzesYamlData.filter((q) => q.language === state.locale.value);
// quiz: get question and tag objects
quizzes.map((q) => {
// get quiz questions + order + only get question ids
Expand Down Expand Up @@ -222,6 +230,9 @@ const store = new Vuex.Store({
UPDATE_ERROR: (state, value) => {
state.error = value;
},
SET_LOCALE_DICT: (state, { dict }) => {
state.locale = dict;
},
SET_CONFIGURATION_DICT: (state, { dict }) => {
state.configuration = dict;
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/views/AboutPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Il est développé par quelques passionés, et a pour but d'évoluer en fonctions des retours utilisateurs :)
</section> -->

<section class="alert alert-warning" role="alert" v-if="$i18n.locale === 'en'">
🌐Page not yet translated ...
</section>

<h3>Pourquoi cette application ?</h3>
<div v-html="configuration.application_about"></div>

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/views/ContributePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<section class="text-align-left">
<h2>Contribuer !</h2>

<section class="alert alert-warning" role="alert" v-if="$i18n.locale === 'en'">
🌐Page not yet translated ...
</section>

<p>
Vous souhaitez rajouter une question ? Ou faire un commentaire sur le contenu existant ?<br />
Envoyez-nous ça en remplissant le petit formulaire ci-dessous 👇
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/views/GlossaryPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<section class="text-align-left">
<h2>Glossaire</h2>

<section class="alert alert-warning" role="alert" v-if="$i18n.locale === 'en'">
🌐Page not yet translated ...
</section>

<p><i>Ces définitions sont ensuite affichées lorsque le mot apparait dans l'énoncé de la question.</i></p>

<br />
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/views/HomePage.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<template>
<section>

<h2 class="special-title">✨&nbsp;{{ $t('messages.newQuizs') }}&nbsp;✨</h2>
<h2 v-if="quizzesSpotlighted && quizzesSpotlighted.length > 0" class="special-title">✨&nbsp;{{ $t('messages.newQuizs') }}&nbsp;✨</h2>
<div class="row" v-if="quizzesSpotlighted && quizzesSpotlighted.length > 0" id="quiz-list">
<div class="col-sm-4" v-for="quiz in quizzesSpotlighted" :key="quiz.id">
<QuizCard :quiz="quiz"/>
</div>
</div>

<div class="row justify-content-md-center margin-bottom-1em">
<div class="col-sm-6" v-if="questionsCount">
<div class="col-sm-6">
<router-link class="no-decoration" :to="{ name: 'quiz-list' }">
<button class="btn btn-primary btn-lg btn-block">
<button id="all-quizs-btn" class="btn btn-primary btn-lg btn-block">
🕹&nbsp;<strong>{{ $t('messages.allQuizs') }}</strong>
</button>
</router-link>
Expand Down Expand Up @@ -64,8 +64,10 @@
</div>

<div class="alert alert-primary" role="alert">
<i v-if="questionsCount">Il y a actuellement <strong>{{ questionsCount }} questions</strong> et <strong>{{ quizzesPublishedCount }} quiz</strong>. </i>
<i><router-link :to="{ name: 'about' }">Aidez-nous</router-link> à en rajouter plus ! </i>
<i>
{{ $t('home.thereIsCurrently') }} <strong>{{ questionsCount }} questions</strong> {{ $t('words.et') }} <strong>{{ quizzesPublishedCount }} quiz</strong>.
<router-link :to="{ name: 'about' }">{{ $t('home.helpUs') }}</router-link> {{ $t('home.toAddMore') }}{{ $t('words.exclamationMark') }}
</i>
</div>
<div v-if="newsletterRegistrationCallback" class="alert alert-success" role="alert">
{{ $t('newsletter.success') }}
Expand All @@ -75,9 +77,9 @@
</div>

<div class="row justify-content-md-center">
<div class="col-sm-6" v-if="questionsCount">
<div class="col-sm-6">
<router-link class="no-decoration" :to="{ name: 'ressources' }">
<button class="btn btn-outline-primary btn-lg btn-block">📚&nbsp;<strong>{{ $t('footer.resources') }}</strong></button>
<button id="resources-btn" class="btn btn-outline-primary btn-lg btn-block">📚&nbsp;<strong>{{ $t('footer.resources') }}</strong></button>
</router-link>
</div>
</div>
Expand All @@ -101,7 +103,7 @@
</div>
</div>
<div class="col-sm-4 text-align-left">
<button class="btn btn-primary" type="submit" :disabled="!emailNewsletterRegistration">Je m'inscris !</button>
<button id="newsletter-btn" class="btn btn-primary" type="submit" :disabled="!emailNewsletterRegistration">Je m'inscris !</button>
</div>
</form>
<div v-if="newsletterRegistrationLoading">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/QuestionDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
v-bind:context="{ question_number: (questionIndex+1)+' / '+questionsDisplayedCount, source: 'question' }"
@answer-submitted="onAnswerSubmitted" />

<div v-if="question" class="question-next small" :key="question.id"> <!-- INFO: :key is to force reload, avoid button staying blur -->
<div v-if="question" class="small" :key="question.id"> <!-- INFO: :key is to force reload, avoid button staying blur -->
<!-- <br /> -->
<router-link v-if="questionSameFilterNextId" :to="{ name: 'question-detail', params: { questionId: questionSameFilterNextId } }">
<button class="btn" :class="emphasisNextButton ? 'btn-primary' : 'btn-outline-primary'">⏩&nbsp;{{ $t('messages.nextQuestion') }}</button>
<button id="question-next-btn" class="btn" :class="emphasisNextButton ? 'btn-primary' : 'btn-outline-primary'">⏩&nbsp;{{ $t('messages.nextQuestion') }}</button>
</router-link>
</div>
</section>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/QuizDetailPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
</div>
</div>

<div v-if="quiz && quizStep === 0" class="quiz-start">
<button class="btn btn-lg btn-primary margin-10" @click="incrementStep()">▶️&nbsp;{{ $t('messages.startQuiz') }}</button>
<div v-if="quiz && quizStep === 0">
<button id="quiz-start-btn" class="btn btn-lg btn-primary margin-10" @click="incrementStep()">▶️&nbsp;{{ $t('messages.startQuiz') }}</button>
</div>

<!-- Quiz en cours -->
Expand Down
1 change: 0 additions & 1 deletion frontend/src/views/QuizListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default {
},
watch: {
// eslint-disable-next-line
},
mounted() {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/views/RessourcesPage.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<template>

<section class="text-align-left">
<h2>Ressources pour aller plus loin</h2>

<section class="alert alert-warning" role="alert" v-if="$i18n.locale === 'en'">
🌐Page not yet translated ...
</section>

<p><i>Table des matières</i></p>
<ol>
<li><a href="#ressources-soutiens">Les associations et les personnes qui participent de près ou de loin au projet</a></li>
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/views/StatsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
<section class="text-align-left">
<h2>Quelques statistiques</h2>

<section class="alert alert-warning" role="alert" v-if="$i18n.locale === 'en'">
🌐Page not yet translated ...
</section>

<p class="text-muted">Mise à jour : {{ data_last_updated }}</p>

<br />
<h3>🕹️&nbsp;Quizs</h3>
<p>
<strong>{{ quiz_count_formatted }}</strong> publiés.
<strong>{{ quiz_published_count_formatted }}</strong> publiés.
<br />
<strong>{{ quiz_answer_count_formatted }}</strong> quizs terminés depuis le lancement
(dont <strong>{{ quiz_answer_count_last_30_days_formatted }}</strong> durant les 30 derniers jours).
Expand Down Expand Up @@ -147,8 +151,9 @@ export default {
const questionPendingValidationCount = this.$store.state.stats.question_per_validation_status_count ? this.$store.state.stats.question_per_validation_status_count.slice(0).find((item) => item.validation_status === constants.QUESTION_VALIDATION_STATUS_IN_PROGRESS).total : 0;
return Intl.NumberFormat('fr-FR').format(questionPendingValidationCount);
},
quiz_count_formatted() {
return Intl.NumberFormat('fr-FR').format(this.$store.state.quizzes.length);
quiz_published_count_formatted() {
const quizPublishedCount = this.$store.state.stats.quiz_per_publish_count ? this.$store.state.stats.quiz_per_publish_count.slice(0).find((item) => item.publish === true).total : 0;
return Intl.NumberFormat('fr-FR').format(quizPublishedCount);
},
question_answer_count_formatted() {
return Intl.NumberFormat('fr-FR').format(this.$store.state.stats.question_answer_count);
Expand Down
Loading

0 comments on commit f0222be

Please sign in to comment.