diff --git a/packages/surveys/src/components/questions/open-text-question.tsx b/packages/surveys/src/components/questions/open-text-question.tsx index ccb8d7ad11..57bb4c3940 100644 --- a/packages/surveys/src/components/questions/open-text-question.tsx +++ b/packages/surveys/src/components/questions/open-text-question.tsx @@ -138,7 +138,7 @@ export function OpenTextQuestion({ tabIndex={isCurrent ? 0 : -1} aria-label="textarea" id={question.id} - placeholder={getLocalizedValue(question.placeholder, languageCode)} + placeholder={getLocalizedValue(question.placeholder, languageCode, true)} dir={dir} required={question.required} value={value} diff --git a/packages/surveys/src/lib/i18n.ts b/packages/surveys/src/lib/i18n.ts index 02207e2b93..9bab640b33 100644 --- a/packages/surveys/src/lib/i18n.ts +++ b/packages/surveys/src/lib/i18n.ts @@ -5,15 +5,31 @@ const isI18nObject = (obj: any): obj is TI18nString => { return typeof obj === "object" && obj !== null && Object.keys(obj).includes("default"); }; -export const getLocalizedValue = (value: TI18nString | undefined, languageId: string): string => { +// Matches \r\n, \n, \r, and their HTML entity variants +const ESCAPED_NEWLINES = /\\r\\n| |\\n|\\r| | /g; + +export const unescapeNewlines = (s: string): string => s.replace(ESCAPED_NEWLINES, "\n"); + +export const getLocalizedValue = ( + value: TI18nString | undefined, + languageId: string, + replaceNewLines: boolean = false +): string => { if (!value) { return ""; } + + let result = ""; + if (isI18nObject(value)) { if (typeof value[languageId] === "string") { - return value[languageId]; + result = value[languageId]; + } else { + result = value.default; } - return value.default; + + result = replaceNewLines ? unescapeNewlines(result) : result; } - return ""; + + return result; };