Skip to content

Commit

Permalink
IP-330: Refactor the solutions related components to use a common tra…
Browse files Browse the repository at this point in the history
…nslation resource
  • Loading branch information
PavlosIsaris committed Dec 17, 2024
1 parent 6880d9d commit 9059096
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
<div class="container">
<div class="row justify-content-center">
<div class="col-10 text-center mx-auto py-5">
<h4 class="mt-0 p-0 mb-5 text-center message">{{ trans("common.sign_in_to_vote") }}</h4>
<a class="btn btn-primary btn-lg w-50" :href="getSignInUrl()">{{ trans("questionnaire.sign_in") }}</a>
<h4 class="mt-0 p-0 mb-5 text-center message">
{{ trans("voting.sign_in_to_vote") }}
</h4>
<a class="btn btn-primary btn-lg w-50" :href="getSignInUrl()">
{{ trans("questionnaire.sign_in") }}
</a>
</div>
</div>
</div>
Expand All @@ -62,10 +66,15 @@
<div class="container">
<div class="row justify-content-center">
<div class="col-10 text-center mx-auto py-5">
<h4 class="mt-0 p-0 mb-5 text-center message">
You can vote up to
<b>{{ questionnaire.max_votes_num }}</b> times.
</h4>
<h4
class="mt-0 p-0 mb-5 text-center message"
v-sane-html="
trans('voting.you_can_vote_up_to', {
votes: questionnaire.max_votes_num,
entityName: trans('voting.entity_questionnaires'),
})
"
></h4>
</div>
</div>
</div>
Expand Down Expand Up @@ -159,7 +168,7 @@
<div class="row">
<div class="col-12">
You are logged in as moderator.
<span v-if="projectFilterSelectedOption == -1">Select a project to filter the responses:</span>
<span v-if="projectFilterSelectedOption === -1">Select a project to filter the responses:</span>
<span v-else>You have filtered the responses, <strong> currently viewing:</strong></span>
<select v-model="projectFilterSelectedOption" @change="onFilterProject($event)">
<option value="-1">View all</option>
Expand All @@ -185,7 +194,8 @@ import { Tabulator } from "survey-analytics/survey.analytics.tabulator";
import CommonModal from "../common/ModalComponent.vue";
import StoreModal from "../common/StoreModalComponent.vue";
import { defineComponent } from "vue";
import transMixin from '../../vue-mixins/trans-mixin';
import transMixin from "../../vue-mixins/trans-mixin";
export default defineComponent({
name: "QuestionnaireStatistics",
mixins: [transMixin],
Expand Down Expand Up @@ -369,7 +379,7 @@ export default defineComponent({
}).then((res) => res.data);
},
getQuestionnaireAnswerAdminAnalysisStatuses() {
if(this.userCanAnnotateAnswers) {
if (this.userCanAnnotateAnswers) {
return this.get({
url: window.route("questionnaire.answers-admin-analysis-statuses.get"),
data: {},
Expand Down Expand Up @@ -508,9 +518,13 @@ export default defineComponent({
element.toggleClass("user-downvoted");
}
const remainingVotes = instance.questionnaire.max_votes_num - instance.numOfVotesByCurrentUser;
let votesWord = "vote";
if (remainingVotes > 1) votesWord += "s";
showToast("You have " + remainingVotes + " " + votesWord + " left!", "#28a745", "bottom-right");
let votesWord = window.trans("voting.votes_remaining_singular");
if (remainingVotes > 1) votesWord = window.trans("voting.votes_remaining_plural");
const message = window.trans("voting.votes_remaining", {
votes: remainingVotes,
votesWord: votesWord,
});
showToast(message, "#28a745", "bottom-right");
} else instance.displayLoginPrompt();
});
},
Expand Down
56 changes: 40 additions & 16 deletions resources/assets/js/vue-components/solution/Solutions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
<div class="container-fluid p-0">
<div class="row pb-4" v-if="userVotesLeft !== null">
<div class="col">
<p style="font-size: 1.429rem; line-height: 1.949rem; text-align: center; margin-bottom: 0">
You can vote for up to {{ maxVotesPerUserForSolutions }} solutions in total.
<!-- bookmark4 - how to translate with dynamic fields? -->
You have {{ userVotesLeft }} more votes remaining.
</p>
<p
style="font-size: 1.429rem; line-height: 1.949rem; text-align: center; margin-bottom: 0"
v-sane-html="getVotesInfoMessage()"
></p>
<p
style="font-size: 1.429rem; line-height: 1.949rem; text-align: center"
v-sane-html="getVotesLeftMessage()"
></p>
</div>
</div>
<div class="row" v-if="errorMessage.length">
<div class="col">
<div class="alert-component position-relative d-none" id="error-alert">
<div class="alert alert-danger" role="alert">
{{ errorMessage }}
<p class="my-2" v-sane-html="errorMessage"></p>
</div>
</div>
</div>
Expand Down Expand Up @@ -106,10 +109,7 @@
</svg>
</div>
<div v-else class="card-custom-img-container">
<img
:src="solution.img_url"
alt="decorative image for solution"
/>
<img :src="solution.img_url" alt="decorative image for solution" />
</div>
<div class="card-body">
<h5 class="card-title">
Expand All @@ -130,7 +130,6 @@
{{ solution.upvotes_count }}
</div>
<div>
<!-- bookmark4 - this div was created to "comment out" the encapsulated content without it being visible in the final markup-->
<ShareCircleButton
:icon-color-theme="buttonTextColorTheme"
:share-url="getSolutionPageURL(solution)"
Expand All @@ -152,9 +151,12 @@ import { mapActions } from "vuex";
import ShareCircleButton from "../common/ShareCircleButton.vue";
import HeartCircleButton from "../common/HeartCircleButton.vue";
import ProposeSolution from "./ProposeSolution.vue";
import transMixin from "../../vue-mixins/trans-mixin";
import { showToast } from "../../common-utils";
export default {
name: "Solutions",
mixins: [transMixin],
components: {
ProposeSolution,
ShareCircleButton,
Expand Down Expand Up @@ -207,6 +209,21 @@ export default {
const b = parseInt(hex.substring(4, 6), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
},
getVotesInfoMessage() {
return trans("voting.you_can_vote_up_to", {
votes: this.maxVotesPerUserForSolutions,
entityName: trans("voting.entity_solutions"),
});
},
getVotesLeftMessage() {
return trans("voting.votes_remaining", {
votes: this.userVotesLeft,
votesWord:
this.userVotesLeft === 1
? trans("voting.votes_remaining_singular")
: trans("voting.votes_remaining_plural"),
});
},
async fetchSolutions() {
this.loading = true;
this.errorMessage = "";
Expand All @@ -221,7 +238,7 @@ export default {
this.checkSolutionInURLAndHighlight();
})
.catch((error) => {
this.showErrorMessage(error); // bookmark4
this.showErrorMessage(error);
})
.finally(() => {
this.loading = false;
Expand Down Expand Up @@ -282,8 +299,15 @@ export default {
if (this.votingInProgress) {
return;
}
if(this.userVotesLeft <= 0) {
this.showErrorMessage("You have no more votes left.");
if (this.userVotesLeft) {
showToast(
trans("voting.votes_remaining", {
votes: 0,
votesWord: trans("voting.votes_remaining_plural"),
}),
"#dc3545",
"bottom-right",
);
return;
}
this.votingInProgress = true;
Expand All @@ -295,7 +319,7 @@ export default {
})
.then((response) => {})
.catch((error) => {
this.showErrorMessage(error); // bookmark4
this.showErrorMessage(error);
})
.finally(() => {
this.votingInProgress = false;
Expand All @@ -310,7 +334,7 @@ export default {
})
.then((response) => {})
.catch((error) => {
this.showErrorMessage(error); // bookmark4
this.showErrorMessage(error);
});
},
updateUpvotesClientSide(solutionId) {
Expand Down
11 changes: 11 additions & 0 deletions resources/lang/bg/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Създайте акаунт или влезте, за да гласувате',
'votes_remaining' => 'Имате <b>:votes</b> :votesWord останали',
'votes_remaining_plural' => 'гласа',
'votes_remaining_singular' => 'глас',
'you_can_vote_up_to' => 'Можете да гласувате до <b>:votes</b> :entityName',
'entity_solutions' => 'решения',
'entity_questionnaires' => 'анкети',
];
11 changes: 11 additions & 0 deletions resources/lang/de/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Erstellen Sie ein Konto oder melden Sie sich an, um abzustimmen',
'votes_remaining' => 'Sie haben noch <b>:votes</b> :votesWord',
'votes_remaining_plural' => 'Stimmen',
'votes_remaining_singular' => 'Stimme',
'you_can_vote_up_to' => 'Sie können bis zu <b>:votes</b> :entityName abstimmen',
'entity_solutions' => 'Lösungen',
'entity_questionnaires' => 'Fragebögen',
];
11 changes: 11 additions & 0 deletions resources/lang/el/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Δημιουργήστε λογαριασμό ή συνδεθείτε για να ψηφίσετε',
'votes_remaining' => 'Έχετε <b>:votes</b> :votesWord απομένουν',
'votes_remaining_plural' => 'ψήφοι',
'votes_remaining_singular' => 'ψήφος',
'you_can_vote_up_to' => 'Μπορείτε να ψηφίσετε έως <b>:votes</b> :entityName',
'entity_solutions' => 'λύσεις',
'entity_questionnaires' => 'ερωτηματολόγια',
];
1 change: 0 additions & 1 deletion resources/lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
'code_of_conduct' => 'Code of Conduct',
'form_fields_required' => 'Fields marked with * are required',
'personal_information_disclaimer' => 'Your personal information (email address) will never be publicly displayed.',
'sign_in_to_vote' => 'Create and account or sign in to vote',
];
11 changes: 11 additions & 0 deletions resources/lang/en/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Create and account or sign in to vote',
'votes_remaining' => 'You have <b>:votes</b> :votesWord left',
'votes_remaining_plural' => 'votes',
'votes_remaining_singular' => 'vote',
'you_can_vote_up_to' => 'You can vote up to <b>:votes</b> :entityName',
'entity_solutions' => 'solutions',
'entity_questionnaires' => 'questionnaires',
];
11 changes: 11 additions & 0 deletions resources/lang/es/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Cree una cuenta o inicie sesión para votar',
'votes_remaining' => 'Le quedan <b>:votes</b> :votesWord',
'votes_remaining_plural' => 'votos',
'votes_remaining_singular' => 'voto',
'you_can_vote_up_to' => 'Puede votar hasta <b>:votes</b> :entityName',
'entity_solutions' => 'soluciones',
'entity_questionnaires' => 'cuestionarios',
];
11 changes: 11 additions & 0 deletions resources/lang/et/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Loo konto või logi sisse, et hääletada',
'votes_remaining' => 'Teil on jäänud <b>:votes</b> :votesWord',
'votes_remaining_plural' => 'häält',
'votes_remaining_singular' => 'hääl',
'you_can_vote_up_to' => 'Saate hääletada kuni <b>:votes</b> :entityName',
'entity_solutions' => 'lahendust',
'entity_questionnaires' => 'küsitlust',
];
11 changes: 11 additions & 0 deletions resources/lang/fr/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Créez un compte ou connectez-vous pour voter',
'votes_remaining' => 'Il vous reste <b>:votes</b> :votesWord',
'votes_remaining_plural' => 'votes',
'votes_remaining_singular' => 'vote',
'you_can_vote_up_to' => 'Vous pouvez voter jusqu\'à <b>:votes</b> :entityName',
'entity_solutions' => 'solutions',
'entity_questionnaires' => 'questionnaires',
];
11 changes: 11 additions & 0 deletions resources/lang/hu/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Hozzon létre egy fiókot, vagy jelentkezzen be a szavazáshoz',
'votes_remaining' => 'Önnek még <b>:votes</b> :votesWord van hátra',
'votes_remaining_plural' => 'szavazat',
'votes_remaining_singular' => 'szavazat',
'you_can_vote_up_to' => 'Ön szavazhat akár <b>:votes</b> :entityName',
'entity_solutions' => 'megoldások',
'entity_questionnaires' => 'kérdőívek',
];
11 changes: 11 additions & 0 deletions resources/lang/it/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Crea un account o accedi per votare',
'votes_remaining' => 'Hai <b>:votes</b> :votesWord rimasti',
'votes_remaining_plural' => 'voti',
'votes_remaining_singular' => 'voto',
'you_can_vote_up_to' => 'Puoi votare fino a <b>:votes</b> :entityName',
'entity_solutions' => 'soluzioni',
'entity_questionnaires' => 'questionari',
];
11 changes: 11 additions & 0 deletions resources/lang/lv/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Izveidojiet kontu vai piesakieties, lai balsotu',
'votes_remaining' => 'Jums ir palikuši <b>:votes</b> :votesWord',
'votes_remaining_plural' => 'balsis',
'votes_remaining_singular' => 'balss',
'you_can_vote_up_to' => 'Jūs varat balsot līdz <b>:votes</b> :entityName',
'entity_solutions' => 'risinājumi',
'entity_questionnaires' => 'aptaujas',
];
11 changes: 11 additions & 0 deletions resources/lang/nl/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Maak een account aan of log in om te stemmen',
'votes_remaining' => 'Je hebt nog <b>:votes</b> :votesWord over',
'votes_remaining_plural' => 'stemmen',
'votes_remaining_singular' => 'stem',
'you_can_vote_up_to' => 'Je kunt tot <b>:votes</b> :entityName stemmen',
'entity_solutions' => 'oplossingen',
'entity_questionnaires' => 'vragenlijsten',
];
11 changes: 11 additions & 0 deletions resources/lang/pt/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Crie uma conta ou faça login para votar',
'votes_remaining' => 'Você tem <b>:votes</b> :votesWord restantes',
'votes_remaining_plural' => 'votos',
'votes_remaining_singular' => 'voto',
'you_can_vote_up_to' => 'Você pode votar até <b>:votes</b> :entityName',
'entity_solutions' => 'soluções',
'entity_questionnaires' => 'questionários',
];
11 changes: 11 additions & 0 deletions resources/lang/sk/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Vytvorte si účet alebo sa prihláste, aby ste mohli hlasovať',
'votes_remaining' => 'Máte <b>:votes</b> :votesWord zostávajúcich',
'votes_remaining_plural' => 'hlasy',
'votes_remaining_singular' => 'hlas',
'you_can_vote_up_to' => 'Môžete hlasovať až do <b>:votes</b> :entityName',
'entity_solutions' => 'riešenia',
'entity_questionnaires' => 'dotazníky',
];
11 changes: 11 additions & 0 deletions resources/lang/sr/voting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'sign_in_to_vote' => 'Kreirajte nalog ili se prijavite da biste glasali',
'votes_remaining' => 'Imate <b>:votes</b> :votesWord preostalo',
'votes_remaining_plural' => 'glasova',
'votes_remaining_singular' => 'glas',
'you_can_vote_up_to' => 'Možete glasati do <b>:votes</b> :entityName',
'entity_solutions' => 'rešenja',
'entity_questionnaires' => 'upitnici',
];

0 comments on commit 9059096

Please sign in to comment.