Skip to content

Commit

Permalink
feat: make new questions translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Jul 17, 2024
1 parent e29a76b commit 7b3b222
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import config from '@plone/volto/registry';
import { defineMessages } from 'react-intl';

const messages = defineMessages({
export const FEEDBACK_THRESHOLD = 3.5;
export const NEGATIVE_FEEDBACK_QUESTIONS = [
'unclear_instructions',
'incomplete_instructions',
'unclear_proceeding',
'technical_problems',
'other_negative',
];
export const POSITIVE_FEEDBACK_QUESTIONS = [
'clear_instructions',
'complete_instructions',
'clear_proceeding',
'no_technical_problems',
'other_positive',
];

export const FEEDBACK_MESSAGES = defineMessages({
unclear_instructions: {
id: 'feedback_unclear_instructions',
defaultMessage: 'Some instructions were not clear and confusing',
Expand Down Expand Up @@ -73,7 +89,9 @@ export const getTranslatedQuestion = (intl, question_id) => {
if (!intl) throw new Error('No intl provided');
if (!question_id) return null;
try {
return intl.formatMessage(messages[question_id]);
return intl.formatMessage(
config.settings['volto-feedback'].questions.messages[question_id],
);
} catch (e) {
throw new Error(
`Cannot translate ${question_id}, no linked translation exists for given parameter`,
Expand Down Expand Up @@ -101,19 +119,3 @@ export const generateFeedbackCommentUUID = (date) => {
// the backend addon work.
return new Date(date).getTime().toString(36);
};

export const NEGATIVE_FEEDBACK_QUESTIONS = [
'unclear_instructions',
'incomplete_instructions',
'unclear_proceeding',
'technical_problems',
'other_negative',
];
export const POSITIVE_FEEDBACK_QUESTIONS = [
'clear_instructions',
'complete_instructions',
'clear_proceeding',
'no_technical_problems',
'other_positive',
];
export const FEEDBACK_THRESHOLD = 3.5;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
NEGATIVE_FEEDBACK_QUESTIONS,
POSITIVE_FEEDBACK_QUESTIONS,
FEEDBACK_THRESHOLD,
FEEDBACK_MESSAGES,
} from 'volto-feedback/helpers';

export {
Expand Down Expand Up @@ -77,6 +78,7 @@ export default function applyConfig(config) {
questions: {
negativeFeedback: NEGATIVE_FEEDBACK_QUESTIONS,
positiveFeedback: POSITIVE_FEEDBACK_QUESTIONS,
messages: FEEDBACK_MESSAGES,
},

formSteps: [
Expand Down

0 comments on commit 7b3b222

Please sign in to comment.