Merge pull request #3762 from southworks/feature/southworks/fix-MultiProviderAuthDialog-localization-ts

[TypeScript][Bot-Solutions] Fix MultiProviderAuthDialog not being localized
This commit is contained in:
lauren-mills 2021-06-02 15:04:34 -07:00 коммит произвёл GitHub
Родитель e4496754ca d7a92d99cd
Коммит db57d22b68
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 150 добавлений и 19 удалений

Просмотреть файл

@ -16,4 +16,6 @@ export class AuthenticationResponses implements IResponseIdCollection {
public static readonly configuredAuthProvidersPrompt: string = 'ConfiguredAuthProvidersPrompt';
public static readonly errorMessageAuthFailure: string = 'ErrorMessageAuthFailure';
public static readonly noLinkedAccount: string = 'NoLinkedAccount';
public static readonly loginButton: string = 'LoginButton';
public static readonly loginPrompt: string = 'LoginPrompt';
}

Просмотреть файл

@ -6,7 +6,8 @@
import { BotFrameworkAdapter, TurnContext } from 'botbuilder';
import { Choice, ChoicePrompt, ComponentDialog, DialogTurnResult, DialogTurnStatus, FoundChoice,
OAuthPrompt, PromptValidatorContext, WaterfallDialog, WaterfallStep, WaterfallStepContext,
OAuthPromptSettings } from 'botbuilder-dialogs';
OAuthPromptSettings,
Dialog} from 'botbuilder-dialogs';
import { TokenStatus } from 'botframework-connector/lib/tokenApi/models';
import { ActionTypes, Activity, ActivityTypes, TokenResponse } from 'botframework-schema';
import i18next from 'i18next';
@ -16,7 +17,6 @@ import { TokenEvents } from '../tokenEvents';
import { AuthenticationResponses } from './authenticationResponses';
import { OAuthProviderExtensions } from './oAuthProviderExtensions';
import { IProviderTokenResponse } from './providerTokenResponse';
import { OAuthProvider } from './oAuthProvider';
enum DialogIds {
providerPrompt = 'ProviderPrompt',
@ -28,6 +28,7 @@ enum DialogIds {
* Provides the ability to prompt for which Authentication provider the user wishes to use.
*/
export class MultiProviderAuthDialog extends ComponentDialog {
private static readonly acceptedLocales: string[] = ['en', 'de', 'es', 'fr', 'it', 'zh'];
private selectedAuthType: string = '';
private authenticationConnections: IOAuthConnection[];
private responseManager: ResponseManager;
@ -42,7 +43,7 @@ export class MultiProviderAuthDialog extends ComponentDialog {
this.authenticationConnections = authenticationConnections;
this.responseManager = new ResponseManager(
['en', 'de', 'es', 'fr', 'it', 'zh'],
MultiProviderAuthDialog.acceptedLocales,
[AuthenticationResponses]
);
@ -65,29 +66,35 @@ export class MultiProviderAuthDialog extends ComponentDialog {
for (var i = 0; i < this.authenticationConnections.length; ++i) {
let connection = this.authenticationConnections[i];
// We ignore placeholder connections in config that don't have a Name
if (connection.name !== undefined && connection.name.trim().length > 0) {
const settings: OAuthPromptSettings = promptSettings[i] || {
connectionName: connection.name,
title: i18next.t('common:login'),
text: i18next.t('common:loginDescription', connection.name)
};
this.addDialog(new OAuthPrompt(
connection.name,
settings,
this.authPromptValidator.bind(this)
));
}
MultiProviderAuthDialog.acceptedLocales.forEach((locale): void => {
this.addDialog(this.getLocalizedDialog(locale, connection.name, promptSettings[i]));
});
};
this.addDialog(new WaterfallDialog(DialogIds.firstStepPrompt, authSteps));
this.addDialog(new WaterfallDialog(DialogIds.authPrompt, authSteps));
this.addDialog(new ChoicePrompt(DialogIds.providerPrompt));
} else {
throw new Error('There is no authenticationConnections value');
}
}
private getLocalizedDialog(locale: string, connectionName: string, settings: OAuthPromptSettings): Dialog {
const loginButtonActivity: string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginButton, locale).text;
const loginPromptActivity: string = this.responseManager.getLocalizedResponse(AuthenticationResponses.loginPrompt, locale, new Map<string, string>([['authType', connectionName]])).text;
settings = settings || {
connectionName: connectionName,
title: loginButtonActivity,
text: loginPromptActivity
};
return new OAuthPrompt(
connectionName + '_' + locale,
settings,
this.authPromptValidator.bind(this)
);
}
// Validators
protected async tokenResponseValidator(promptContext: PromptValidatorContext<Activity>): Promise<boolean> {
const activity: Activity | undefined = promptContext.recognized.value;
@ -107,7 +114,7 @@ export class MultiProviderAuthDialog extends ComponentDialog {
private async promptForProvider(stepContext: WaterfallStepContext): Promise<DialogTurnResult> {
if (this.authenticationConnections.length === 1) {
const result: string = this.authenticationConnections[0].name;
const result: string = this.authenticationConnections[0].name + '_' + i18next.language.split('-')[0];
return await stepContext.next(result);
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "expectingInput"
},
"LoginButton": {
"replies": [
{
"text": "Einloggen",
"speak": "Einloggen"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "Melden Sie sich in Ihrem {authType}-Konto an",
"speak": "Melden Sie sich in Ihrem {authType}-Konto an"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "expectingInput"
},
"LoginButton": {
"replies": [
{
"text": "Iniciar sesión",
"speak": "Iniciar sesión"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "Inicia sesión en tu cuenta de {authType}",
"speak": "Inicia sesión en tu cuenta de {authType}"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "expectingInput"
},
"LoginButton": {
"replies": [
{
"text": "s'identifier",
"speak": "s'identifier"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "connectez-vous à votre compte {authType}",
"speak": "connectez-vous à votre compte {authType}"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "expectingInput"
},
"LoginButton": {
"replies": [
{
"text": "Accesso",
"speak": "Accesso"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "Accedi al tuo account {authType}",
"speak": "Accedi al tuo account {authType}"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "acceptingInput"
},
"LoginButton": {
"replies": [
{
"text": "Login",
"speak": "Login"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "Sign in to your {authType} account",
"speak": "Sign in to your {authType} account"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -43,5 +43,23 @@
}
],
"inputHint": "expectingInput"
},
"LoginButton": {
"replies": [
{
"text": "登錄",
"speak": "登錄"
}
],
"inputHint": "acceptingInput"
},
"LoginPrompt": {
"replies": [
{
"text": "登錄到您的{authType}帳戶",
"speak": "登錄到您的{authType}帳戶"
}
],
"inputHint": "acceptingInput"
}
}

Просмотреть файл

@ -56,6 +56,20 @@ export class ResponseManager {
return this.parseResponse(template, tokens);
}
/**
* Gets a simple response from template with Text, Speak, InputHint, and SuggestedActions set.
* @param templateId The name of the response template.
* @param locale The locale for the response template.
* @param tokens string map of tokens to replace in the response.
* @returns An Activity.
*/
public getLocalizedResponse(templateId: string, locale: string, tokens?: Map<string, string>): Partial<Activity> {
const template: ResponseTemplate = this.getResponseTemplate(templateId, locale);
// create the response the data items
return this.parseResponse(template, tokens);
}
/**
* Gets the Text of a response.
* @param templateId The name of the response template.