Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Italian Support for Confirm/Choice Prompts #1500

Merged
merged 11 commits into from
Feb 22, 2020
Next Next commit
- added Italian support
- Added PromptCultureModels tests
mdrichardson committed Dec 12, 2019
commit f042c6ba8f04230bfb47d568045725f3ae2f8285
8 changes: 4 additions & 4 deletions libraries/botbuilder-dialogs/package.json
Original file line number Diff line number Diff line change
@@ -20,10 +20,10 @@
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"dependencies": {
"@microsoft/recognizers-text-choice": "1.1.4",
"@microsoft/recognizers-text-date-time": "1.1.4",
"@microsoft/recognizers-text-number": "1.1.4",
"@microsoft/recognizers-text-suite": "1.1.4",
"@microsoft/recognizers-text-choice": "^1.1.4",
"@microsoft/recognizers-text-date-time": "^1.1.4",
"@microsoft/recognizers-text-number": "^1.1.4",
"@microsoft/recognizers-text-suite": "^1.1.4",
"@types/node": "^10.12.18",
"botbuilder-core": "4.1.6",
"globalize": "^1.4.2"
11 changes: 11 additions & 0 deletions libraries/botbuilder-dialogs/src/prompts/promptCultureModels.ts
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ export interface PromptCultureModel {
* Class container for currently-supported Culture Models in Confirm and Choice Prompt.
*/
export class PromptCultureModels {

public static Chinese: PromptCultureModel = {
locale: Culture.Chinese,
separator: ', ',
@@ -88,6 +89,15 @@ export class PromptCultureModels {
noInLanguage: 'Nein',
}

public static Italian: PromptCultureModel = {
locale: Culture.Italian,
separator: ', ',
inlineOr: ' o ',
inlineOrMore: ' o ',
yesInLanguage: 'Si',
noInLanguage: 'No',
}

public static Japanese: PromptCultureModel = {
locale: Culture.Japanese,
separator: '、 ',
@@ -152,6 +162,7 @@ export class PromptCultureModels {
PromptCultureModels.English,
PromptCultureModels.French,
PromptCultureModels.German,
PromptCultureModels.Italian,
PromptCultureModels.Japanese,
PromptCultureModels.Portuguese,
PromptCultureModels.Spanish,
1 change: 1 addition & 0 deletions libraries/botbuilder-dialogs/tests/choicePrompt.test.js
Original file line number Diff line number Diff line change
@@ -341,6 +341,7 @@ describe('ChoicePrompt', function () {
'en-us',
'fr-fr',
'de-de',
'it-it',
'ja-jp',
'pt-br',
'zh-cn'
5 changes: 3 additions & 2 deletions libraries/botbuilder-dialogs/tests/confirmPrompt.test.js
Original file line number Diff line number Diff line change
@@ -322,6 +322,7 @@ describe('ConfirmPrompt', function () {
'fr-fr',
'de-de',
'ja-jp',
'it-it',
'pt-br',
'zh-cn'
];
@@ -556,7 +557,7 @@ describe('ConfirmPrompt', function () {
.assertReply(`The result found is 'true'.`);
});

it('should recogize valid number and default to en if locale invalid string.', async function () {
it('should recognize valid number and default to en if locale invalid string.', async function () {
const adapter = new TestAdapter(async (turnContext) => {

turnContext.activity.locale = 'invalid-locale';
@@ -591,7 +592,7 @@ describe('ConfirmPrompt', function () {
.assertReply(`The result found is 'true'.`);
});

it('should recogize valid number and default to en if defaultLocale invalid string.', async function () {
it('should recognize valid number and default to en if defaultLocale invalid string.', async function () {
const adapter = new TestAdapter(async (turnContext) => {

const dc = await dialogs.createContext(turnContext);
73 changes: 73 additions & 0 deletions libraries/botbuilder-dialogs/tests/promptCultureModels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const assert = require('assert');
const { PromptCultureModels } = require('../lib')

describe('Prompt Culture Models Tests', function() {
this.timeout(5000);

it('should correctly map to nearest language', function() {
const locales = [
'es-es',
'nl-nl',
'en-us',
'fr-fr',
'de-de',
'ja-jp',
'it-it',
'pt-br',
'zh-cn'
];
// es-ES
const capEnding = (locale) => {
return `${ locale.split('-')[0] }-${ locale.split('-')[1].toUpperCase() }`;
};
// es-Es
const titleEnding = (locale) => {
locale[3] = locale.charAt(3).toUpperCase();
return locale;
};
// ES
const capTwoLetter = (locale) => {
return locale.split('-')[0].toUpperCase();
};
// es
const lowerTwoLetter = (locale) => {
return locale.split('-')[0].toLowerCase();
};

// This creates an object of the correct locale along with its test locales
const localeTests = locales.reduce((obj, locale) => {
obj[locale] = [
locale,
capEnding(locale),
titleEnding(locale),
capTwoLetter(locale),
lowerTwoLetter(locale)
];
return obj;
}, {});

Object.keys(localeTests).map((validLocale) => {
localeTests[validLocale].map((testLocale) => {
assert.strictEqual(PromptCultureModels.mapToNearestLanguage(testLocale), validLocale);
});
});
});

it('should return all supported cultures', function() {
const expected = [
PromptCultureModels.Chinese,
PromptCultureModels.Dutch,
PromptCultureModels.English,
PromptCultureModels.French,
PromptCultureModels.German,
PromptCultureModels.Italian,
PromptCultureModels.Japanese,
PromptCultureModels.Portuguese,
PromptCultureModels.Spanish
];

const supportedCultures = PromptCultureModels.getSupportedCultures();

assert.deepEqual(supportedCultures, expected);
});
});