Skip to content

Commit

Permalink
fix: auto translate ui if not multilingual
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Oct 10, 2024
1 parent 4a737c0 commit 754f6a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/components/MemoriWidget/MemoriWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ const MemoriWidget = ({
* Sets the language in the i18n instance
*/
useEffect(() => {
if (userLang && uiLanguages.includes(userLang.toLowerCase())) {
if (
isMultilanguageEnabled &&
userLang &&
uiLanguages.includes(userLang.toLowerCase())
) {
// @ts-ignore
i18n.changeLanguage(userLang.toLowerCase());
}
Expand Down Expand Up @@ -1971,9 +1975,14 @@ const MemoriWidget = ({
//if there is an emotion, remove the tag <output > from the text
const textToSpeak = text.replace(/<output>(.*?)<\/output>/g, '$1');

speechSynthesizer.speakSsmlAsync(`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(
speechSynthesizer.speakSsmlAsync(
`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" xml:lang="${getCultureCodeByLanguage(
userLang
)}"><voice name="${getTTSVoice(
userLang
)}"><voice name="${getTTSVoice(userLang)}"><mstts:express-as style="${getAzureStyleForEmotion(emotion)}"><s>${replaceTextWithPhonemes(
)}"><mstts:express-as style="${getAzureStyleForEmotion(
emotion
)}"><s>${replaceTextWithPhonemes(
escapeHTML(stripMarkdown(stripEmojis(stripOutputTags(textToSpeak)))),
userLang.toLowerCase()
)}</s></mstts:express-as></voice></speak>`,
Expand Down
10 changes: 4 additions & 6 deletions src/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,11 @@ WithCustomUserAvatar.args = {

export const Test = Template.bind({});
Test.args = {
ownerUserName: 'memoridev',
memoriName: 'Assistente Report',
tenantID: 'bcc-iccrea.aclambda.online',
apiURL: 'https://backend.memori.ai',
baseURL: 'https://bcc-iccrea.aclambda.online',
ownerUserName: 'dpezzettone',
memoriName: 'Meta Prompt Engineer',
tenantID: 'www.aisuru.com',
layout: 'CHAT',
uiLang: 'it',
uiLang: 'en',
showShare: true,
showSettings: true,
showLogin: true,
Expand Down

0 comments on commit 754f6a8

Please sign in to comment.