From d538d5d0538a146eb323c45814da00bb67a7375c Mon Sep 17 00:00:00 2001 From: Chris Garrity Date: Fri, 1 May 2020 12:09:19 -0400 Subject: [PATCH] Localize the widget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that some of the Freshdesk locales don’t match the ones used by Scratch. --- src/components/helpwidget/helpwidget.jsx | 37 +++++++++++++++++++++++- src/l10n.json | 4 +++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/components/helpwidget/helpwidget.jsx b/src/components/helpwidget/helpwidget.jsx index 127200ca1..0eb6ea1ca 100644 --- a/src/components/helpwidget/helpwidget.jsx +++ b/src/components/helpwidget/helpwidget.jsx @@ -9,6 +9,30 @@ const React = require('react'); const Button = require('../forms/button.jsx'); const Spinner = require('../spinner/spinner.jsx'); require('./helpwidget.scss'); + +// map Scratch locale to supported Freshdesk locale +const freshdeskLocale = locale => { + // most locales in Scratch and Freshdesk use the two letter code. Define exceptions: + const localeMap = { + 'es-419': 'es-LA', + 'ja': 'ja-JP', + 'ja-Hira': 'ja-JP', + 'lv': 'lv-LV', + 'nb': 'nb-NO', + 'nn': 'nb-NO', + 'pt': 'pt-PT', + 'pt-br': 'pt-BR', + 'ru': 'ru-RU', + 'sv': 'sv-SE', + 'zh-cn': 'zh-CN', + 'zh-tw': 'zh-TW' + }; + if (localeMap.hasOwnProperty(locale)) { + return localeMap[locale]; + } + // locale will either be supported by Freshdesk, or will default to English if not + return locale; +}; /** * Button or link that opens the Freshdesk Help widget * see https://developers.freshdesk.com/widget-api/ @@ -46,7 +70,7 @@ class HelpWidget extends React.Component { window.fwSettings = { widget_id: 4000000089, - locale: this.props.intl.locale + locale: freshdeskLocale(this.props.intl.locale) }; document.body.appendChild(script); } @@ -59,6 +83,17 @@ class HelpWidget extends React.Component { // don't show the Freshdesk button window.FreshworksWidget('hide', 'launcher'); + const labels = {}; + labels[freshdeskLocale(this.props.intl.locale)] = { + banner: this.props.intl.formatMessage({id: 'helpWidget.banner'}), + contact_form: { + title: this.props.intl.formatMessage({id: 'general.contactUs'}), + submit: this.props.intl.formatMessage({id: 'helpWidget.submit'}), + confirmation: this.props.intl.formatMessage({id: 'helpWidget.confirmation'}) + } + }; + window.FreshworksWidget('setLabels', labels); + window.FreshworksWidget('disable', 'ticketForm', ['custom_fields.cf_inappropriate_report_link']); window.FreshworksWidget('hide', 'ticketForm', ['custom_fields.cf_inappropriate_report_link']); diff --git a/src/l10n.json b/src/l10n.json index 348d19b70..0b80ef54e 100644 --- a/src/l10n.json +++ b/src/l10n.json @@ -355,6 +355,10 @@ "social.copyLinkLinkText": "Copy link", "social.embedCopiedResultText": "Copied", + "helpWidget.banner": "Welcome to Support", + "helpWidget.submit": "Send", + "helpWidget.confirmation": "Thank you for your message.", + "bluetooth.enableLocationServicesTitle": "Make sure you have location services enabled on Chromebooks or Android tablets", "bluetooth.enableLocationServicesText": "Bluetooth can be used to provide location data to the app. In addition to granting the Scratch App permission to access location, location must be enabled in your general device settings. Search for 'Location' in your settings, and make sure it is on. On Chromebooks search for 'Location' in the Google Play Store Android preferences." }