Localize the widget

Note that some of the Freshdesk locales don’t match the ones used by Scratch.
This commit is contained in:
Chris Garrity 2020-05-01 12:09:19 -04:00
parent 23980e1f23
commit d538d5d053
2 changed files with 40 additions and 1 deletions

View file

@ -9,6 +9,30 @@ const React = require('react');
const Button = require('../forms/button.jsx'); const Button = require('../forms/button.jsx');
const Spinner = require('../spinner/spinner.jsx'); const Spinner = require('../spinner/spinner.jsx');
require('./helpwidget.scss'); 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 * Button or link that opens the Freshdesk Help widget
* see https://developers.freshdesk.com/widget-api/ * see https://developers.freshdesk.com/widget-api/
@ -46,7 +70,7 @@ class HelpWidget extends React.Component {
window.fwSettings = { window.fwSettings = {
widget_id: 4000000089, widget_id: 4000000089,
locale: this.props.intl.locale locale: freshdeskLocale(this.props.intl.locale)
}; };
document.body.appendChild(script); document.body.appendChild(script);
} }
@ -59,6 +83,17 @@ class HelpWidget extends React.Component {
// don't show the Freshdesk button // don't show the Freshdesk button
window.FreshworksWidget('hide', 'launcher'); 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('disable', 'ticketForm', ['custom_fields.cf_inappropriate_report_link']);
window.FreshworksWidget('hide', 'ticketForm', ['custom_fields.cf_inappropriate_report_link']); window.FreshworksWidget('hide', 'ticketForm', ['custom_fields.cf_inappropriate_report_link']);

View file

@ -355,6 +355,10 @@
"social.copyLinkLinkText": "Copy link", "social.copyLinkLinkText": "Copy link",
"social.embedCopiedResultText": "Copied", "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.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." "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."
} }