Skip to content

Commit 00da406

Browse files
compulimcorinagum
authored andcommitted
Fallback to en-US for date time formatting (#2286)
* Fallback to en-US * Add test * Update PR number * Fix eslint
1 parent cc808b5 commit 00da406

4 files changed

Lines changed: 39 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7373
- Fix [#2245](https://github.com/microsoft/BotFramework-WebChat/issues/2245). Fix speech synthesis not working on Safari by priming the engine on the first microphone button click, by [@compulim](https://github.com/compulim) in PR [#2246](https://github.com/microsoft/BotFramework-WebChat/pull/2246)
7474
- Fix [#1514](https://github.com/microsoft/BotFramework-WebChat/issues/1514). Added reference grammar ID when using Cognitive Services Speech Services, by [@compulim](https://github.com/compulim) in PR [#2246](https://github.com/microsoft/BotFramework-WebChat/pull/2246)
7575
- Fix [#1515](https://github.com/microsoft/BotFramework-WebChat/issues/1515). Added dynamic phrases when using Cognitive Services Speech Services, by [@compulim](https://github.com/compulim) in PR [#2246](https://github.com/microsoft/BotFramework-WebChat/pull/2246)
76+
- Fix [#2273](https://github.com/microsoft/BotFramework-WebChat/issues/2273). Add `ScreenReaderText` component, by [@corinagum](https://github.com/corinagum) in PR [#2278](https://github.com/microsoft/BotFramework-WebChat/pull/2278)
77+
- Fix [#2231](https://github.com/microsoft/BotFramework-WebChat/issues/2231). Fallback to English (US) if date time formatting failed, by [@compulim](https://github.com/compulim) in PR [#2286](https://github.com/microsoft/BotFramework-WebChat/pull/2286)
7678

7779
### Added
7880

14.4 KB
Loading

__tests__/language.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { imageSnapshotOptions, timeouts } from './constants.json';
2+
3+
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
4+
import uiConnected from './setup/conditions/uiConnected';
5+
6+
// selenium-webdriver API doc:
7+
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html
8+
9+
jest.setTimeout(timeouts.test);
10+
11+
test('setting language to empty string should not crash', async () => {
12+
const { driver, pageObjects } = await setupWebDriver();
13+
14+
await driver.wait(uiConnected(), timeouts.directLine);
15+
await pageObjects.sendMessageViaSendBox('echo Hello', { waitForSend: true });
16+
17+
await driver.wait(minNumActivitiesShown(2), timeouts.directLine);
18+
19+
const base64PNG = await driver.takeScreenshot();
20+
21+
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
22+
});
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
2+
13
export default function getLocaleString(value, language) {
24
const date = new Date(value);
35
const options = {
@@ -8,8 +10,17 @@ export default function getLocaleString(value, language) {
810
month: 'long'
911
};
1012

11-
if (window.Intl) {
12-
return !!date && new Intl.DateTimeFormat(language, options).format(date);
13-
}
14-
return date.toLocaleDateString(language, options);
13+
try {
14+
if (window.Intl) {
15+
return !!date && new Intl.DateTimeFormat(language, options).format(date);
16+
}
17+
} catch (err) {}
18+
19+
try {
20+
return date.toLocaleDateString(language, options);
21+
} catch (err) {}
22+
23+
// Fallback to en-US if failed, for example, invalid language code would throw exception
24+
25+
return date.toLocaleDateString('en-US', options);
1526
}

0 commit comments

Comments
 (0)