Skip to content

Commit

Permalink
Fixed questionnaire translation process
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Dec 3, 2024
1 parent 47d0596 commit e8771cb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function saveLanguagesForQuestionnaire(array $lang_codes, int $questionna
$existingQuestionnaireLanguages = $this->getLanguagesForQuestionnaire($questionnaire_id);
$languagesToDelete = $existingQuestionnaireLanguages->pluck('language.language_code')->toArray();
for ($i = 0; $i < count($lang_codes); $i++) {
// fix for Greek language code
if ($lang_codes[$i] === 'gr') {
$lang_codes[$i] = 'el';
}
if (in_array($lang_codes[$i], $languagesToDelete)) {
array_splice($languagesToDelete, array_search($lang_codes[$i], $languagesToDelete), 1);
}
Expand Down
5 changes: 5 additions & 0 deletions app/Utils/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Translator {
* @throws \Exception
*/
public static function translateTexts(array $texts, string $lang_code): array {
// fix for Greek language code
if ($lang_code === 'gr') {
$lang_code = 'el';
}

$translate = new TranslateClient(['key' => config('app.google_translate_key')]);
// Google translate capacity is 100 texts per request.
// So we need to break the texts into 100-texts batches
Expand Down
54 changes: 2 additions & 52 deletions resources/assets/js/vue-components/common/StoreModalComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<button
tabindex="-1"
type="button"
class="mx-auto btn btn-primary"
class="mx-auto btn btn-primary btn-slim"
@click="$emit('okClicked')"
>
Close
Expand Down Expand Up @@ -92,55 +92,5 @@ export default {

<style scoped lang="scss">
@import "../../../sass/_variables.scss";
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}
.modal-container {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: top;
padding-top: 10%;
.modal-container {
box-shadow: none;
}
}
.modal-body {
padding-bottom: 2rem;
padding-top: 2rem;
.message {
color: $green;
word-break: break-word;
}
}
.modal-enter {
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
@import "resources/assets/sass/shared/modal";
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@
</div>
</div>

<hr class="my-5" />

<div class="row mb-3">
<div class="col-12">
<button
class="btn btn-primary"
class="btn btn-primary btn-slimmer"
type="button"
data-toggle="collapse"
data-target="#collapseHelpFileType"
Expand Down Expand Up @@ -573,7 +575,7 @@ export default defineComponent({
this.surveyCreator.changeText(response.data.translation);
this.surveyCreator.showTranslationEditor();
this.modalOpen = false;
showToast("Translations generated!", "#28a745", "bottom-right");
showToast("Translations generated! Don't forget to Save the questionnaire!", "#28a745", "bottom-right", 7000);
} catch (error) {
console.error(error);
this.modalOpen = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="modal-component">
<common-modal :open="modalOpen" :allow-close="true" :classes="''" @canceled="$emit('canceled')">
<common-modal :open="modalOpen" :allow-close="false">
<template #header>
<h5 class="modal-title pl-2">
Mark Questionnaire Languages<span
Expand Down Expand Up @@ -51,7 +51,7 @@
<div class="col-3 offset-6 pr-0">
<button
type="button"
class="btn btn-outline-secondary btn-lg w-100"
class="btn btn-outline-secondary btn-slim w-100"
@click="$emit('canceled')"
>
Cancel
Expand All @@ -61,7 +61,7 @@
<button
:disabled="saveLoading"
type="button"
class="btn btn-primary btn-lg w-100"
class="btn btn-primary btn-slim w-100 "
@click="saveQuestionnaireLanguagesStatus"
>
Save<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ export default defineComponent({
}).then((res) => res.data);
},
getQuestionnaireAnswerAdminAnalysisStatuses() {
return this.get({
url: window.route("questionnaire.answers-admin-analysis-statuses.get"),
data: {},
urlRelative: false,
}).then((res) => res.data);
if(this.userCanAnnotateAnswers) {
return this.get({
url: window.route("questionnaire.answers-admin-analysis-statuses.get"),
data: {},
urlRelative: false,
}).then((res) => res.data);
}
},
initStatistics(answers, answerVotes, answerAnnotations, adminAnalysisStatuses) {
// remove from the questions array the questions that should not be displayed in the statistics
Expand Down
51 changes: 51 additions & 0 deletions resources/assets/sass/shared/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,54 @@
}
}
}

.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}

.modal-container {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
}

.modal-wrapper {
display: table-cell;
vertical-align: top;
padding-top: 10%;

.modal-container {
box-shadow: none;
}
}

.modal-body {
padding-bottom: 2rem;
padding-top: 2rem;

.message {
color: $green;
word-break: break-word;
}
}

.modal-enter {
opacity: 0;
}

.modal-leave-active {
opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}

0 comments on commit e8771cb

Please sign in to comment.