From 1f7d8dcaafc27d09ebea765c92ea5a0c876e5e32 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Sun, 4 Oct 2020 20:58:35 +0530 Subject: [PATCH 1/3] Add multiple language support --- config/Settings.ts | 41 +++++++++++++++++++++++++++++++++++++++++ i18n/en.json | 3 ++- lib/Dialogflow.ts | 4 +++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/config/Settings.ts b/config/Settings.ts index f52cb84..1e7650c 100644 --- a/config/Settings.ts +++ b/config/Settings.ts @@ -11,6 +11,7 @@ export enum AppSetting { DialogflowServiceUnavailableMessage = 'dialogflow_service_unavailable_message', DialogflowCloseChatMessage = 'dialogflow_close_chat_message', DialogflowHideQuickReplies = 'dialogflow_hide_quick_replies', + DialogflowLanguage = 'dialogflow_language', } export enum DefaultMessage { @@ -19,6 +20,36 @@ export enum DefaultMessage { DEFAULT_DialogflowCloseChatMessage = 'Closing the chat, Goodbye', } +export const LanguageCode = [ + { key: 'zh-CN', i18nLabel: 'chinese_simplified' }, + { key: 'da', i18nLabel: 'danish' }, + { key: 'nl', i18nLabel: 'dutch' }, + { key: 'en', i18nLabel: 'english' }, + { key: 'en-AU', i18nLabel: 'english_australia' }, + { key: 'en-CA', i18nLabel: 'english_canada' }, + { key: 'en-GB', i18nLabel: 'english_great_britain' }, + { key: 'en-IN', i18nLabel: 'english_india' }, + { key: 'en-US', i18nLabel: 'english_us' }, + { key: 'fr-CA', i18nLabel: 'french_canada' }, + { key: 'fr-FR', i18nLabel: 'french_france' }, + { key: 'de', i18nLabel: 'german' }, + { key: 'hi', i18nLabel: 'hindi' }, + { key: 'id', i18nLabel: 'indonesian' }, + { key: 'it', i18nLabel: 'italian' }, + { key: 'ja', i18nLabel: 'japanese' }, + { key: 'ko', i18nLabel: 'korean' }, + { key: 'no', i18nLabel: 'norwegian' }, + { key: 'pl', i18nLabel: 'polish' }, + { key: 'pt-BR', i18nLabel: 'portuguese-brazil' }, + { key: 'pt', i18nLabel: 'portuguese-portugal' }, + { key: 'ru', i18nLabel: 'russian' }, + { key: 'es', i18nLabel: 'spanish' }, + { key: 'es-ES', i18nLabel: 'spanish-spain' }, + { key: 'sv', i18nLabel: 'swedish' }, + { key: 'tr', i18nLabel: 'turkish' }, + { key: 'uk', i18nLabel: 'ukrainian' }, +]; + export const settings: Array = [ { id: AppSetting.DialogflowBotUsername, @@ -71,6 +102,16 @@ export const settings: Array = [ i18nDescription: 'target_department_for_handover_description', required: false, }, + { + id: AppSetting.DialogflowLanguage, + public: true, + type: SettingType.SELECT, + values: LanguageCode, + packageValue: 'en', + value: 'en', + i18nLabel: 'dialogflow_language', + required: true, + }, { id: AppSetting.DialogflowHandoverMessage, public: true, diff --git a/i18n/en.json b/i18n/en.json index fa36e66..1f36045 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -14,5 +14,6 @@ "dialogflow_close_chat_message": "Close Chat Message", "dialogflow_close_chat_message_description": "This message will be sent automatically when a chat is closed", "dialogflow_hide_quick_replies": "Hide Quick Replies", - "dialogflow_hide_quick_replies_description": "If enabled, then all quick-replies will hide when a visitor clicks on any one of them" + "dialogflow_hide_quick_replies_description": "If enabled, then all quick-replies will hide when a visitor clicks on any one of them", + "dialogflow_language": "Language" } diff --git a/lib/Dialogflow.ts b/lib/Dialogflow.ts index c26bf97..2bfca27 100644 --- a/lib/Dialogflow.ts +++ b/lib/Dialogflow.ts @@ -20,9 +20,11 @@ class DialogflowClass { requestType: DialogflowRequestType): Promise { const serverURL = await this.getServerURL(read, modify, http, sessionId); + const languageCode = await getAppSettingValue(read, AppSetting.DialogflowLanguage); + const queryInput = { ...requestType === DialogflowRequestType.EVENT && { event: request }, - ...requestType === DialogflowRequestType.MESSAGE && { text: { languageCode: LanguageCode.EN, text: request } }, + ...requestType === DialogflowRequestType.MESSAGE && { text: { languageCode, text: request } }, }; const httpRequestContent: IHttpRequest = createHttpRequest( From b1c43f6636ee496095755c365f5825c30a27bf06 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Mon, 5 Oct 2020 09:51:12 +0530 Subject: [PATCH 2/3] Add i18n labels --- i18n/en.json | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/i18n/en.json b/i18n/en.json index 1f36045..20b635d 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -15,5 +15,32 @@ "dialogflow_close_chat_message_description": "This message will be sent automatically when a chat is closed", "dialogflow_hide_quick_replies": "Hide Quick Replies", "dialogflow_hide_quick_replies_description": "If enabled, then all quick-replies will hide when a visitor clicks on any one of them", - "dialogflow_language": "Language" + "dialogflow_language": "Language", + "chinese_simplified": "Chinese - Simplified", + "danish": "Danish", + "dutch": "Dutch", + "english": "English", + "english_australia": "English - Australia", + "english_canada": "English - Canada", + "english_great_britain": "English - Great Britain", + "english_india": "English - India", + "english_us": "English - US", + "french_canada": "French - Canada", + "french_france": "French - France", + "german": "German", + "hindi": "Hindi", + "indonesian": "Indonesian", + "italian": "Italian", + "japanese": "Japanese", + "korean": "Korean", + "norwegian": "Norwegian", + "polish": "Polish", + "portuguese-brazil": "Portuguese - Brazil", + "portuguese-portugal": "Portuguese - Portugal", + "russian": "Russian", + "spanish": "Spanish", + "spanish-spain": "Spanish - Spain", + "swedish": "Swedish", + "turkish": "Turkish", + "ukrainian": "Ukrainian" } From fa7bb8bf70e1756e089200fefe673315a00511a4 Mon Sep 17 00:00:00 2001 From: murtaza98 Date: Tue, 6 Oct 2020 23:11:34 +0530 Subject: [PATCH 3/3] add multiple lang support for audio message --- lib/Dialogflow.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dialogflow.ts b/lib/Dialogflow.ts index 0a3653b..62b72ef 100644 --- a/lib/Dialogflow.ts +++ b/lib/Dialogflow.ts @@ -25,9 +25,9 @@ class DialogflowClass { const queryInput = { ...requestType === DialogflowRequestType.EVENT && { event: request }, ...requestType === DialogflowRequestType.MESSAGE && { text: { languageCode, text: request } }, - ...requestType === DialogflowRequestType.AUDIO && { audioConfig: { languageCode: AudioLanguageCode.EN_US } }, + ...requestType === DialogflowRequestType.AUDIO && { audioConfig: { languageCode } }, ...requestType === DialogflowRequestType.AUDIO_OGG && - { audioConfig: { audioEncoding: DialogflowInputAudioEncoding.ENCODING_OGG, sampleRateHertz: 16000, languageCode: AudioLanguageCode.EN_US } }, + { audioConfig: { audioEncoding: DialogflowInputAudioEncoding.ENCODING_OGG, sampleRateHertz: 16000, languageCode } }, }; const { value: onlyTextMessage } = await read.getEnvironmentReader().getSettings().getById(AppSetting.DialogflowShowOnlyTextMessages);