Skip to content

Commit f8bd560

Browse files
committed
Bug fixes around localization
1 parent 64370bf commit f8bd560

File tree

9 files changed

+36
-26
lines changed

9 files changed

+36
-26
lines changed

Node/core/src/DefaultLocalizer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ export class DefaultLocalizer implements ILocalizer {
4747
constructor() {
4848
}
4949

50-
initialize(settings?: ILocalizerSettings) {
51-
if (!settings) {
52-
return;
53-
}
54-
50+
initialize(settings: ILocalizerSettings = {}) {
5551
if (settings.botLocalePath) {
5652
this.botLocalePath = settings.botLocalePath.toLowerCase();
5753
if (this.botLocalePath.charAt(this.botLocalePath.length - 1) != '/') {

Node/core/src/Session.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ export class Session extends events.EventEmitter implements ISession {
119119
this.message.type = consts.messageType;
120120
}
121121

122-
// Localize message, then invoke middleware
123-
logger.debug("loading localizer for: " + this.message.textLocale)
124-
this.localizer.load(this.message.textLocale, (err:Error) => {
122+
// Ensure localized prompts are loaded
123+
var locale = this.preferredLocale();
124+
this.localizer.load(locale, (err:Error) => {
125125
if (err) {
126126
this.error(err);
127127
} else {
@@ -140,9 +140,19 @@ export class Session extends events.EventEmitter implements ISession {
140140
public localizer:ILocalizer = null;
141141

142142
public error(err: Error): ISession {
143-
err = err instanceof Error ? err : new Error(err.toString());
144143
logger.info(this, 'session.error()');
145-
this.endConversation(this.options.dialogErrorMessage || 'Oops. Something went wrong and we need to start over.');
144+
145+
// End conversation with a message
146+
if (this.options.dialogErrorMessage) {
147+
this.endConversation(this.options.dialogErrorMessage);
148+
} else {
149+
var locale = this.preferredLocale();
150+
this.endConversation(this.localizer.gettext(locale, 'default_error', consts.Library.system));
151+
}
152+
153+
// Log error
154+
var m = err.toString();
155+
err = err instanceof Error ? err : new Error(m);
146156
this.emit('error', err);
147157
return this;
148158
}

Node/core/src/bots/ChatConnector.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ export class ChatConnector implements ub.IConnector, bs.IBotStorage {
317317
if (!err) {
318318
callback(null, data);
319319
} else {
320-
callback(err instanceof Error ? err : new Error(err.toString()), null);
320+
var m = err.toString();
321+
callback(err instanceof Error ? err : new Error(m), null);
321322
}
322323
});
323324
} catch (e) {
@@ -399,14 +400,15 @@ export class ChatConnector implements ub.IConnector, bs.IBotStorage {
399400
if (!err) {
400401
callback(null);
401402
} else {
402-
callback(err instanceof Error ? err : new Error(err.toString()));
403+
var m = err.toString();
404+
callback(err instanceof Error ? err : new Error(m));
403405
}
404406
}
405407
});
406408
} catch (e) {
407409
if (callback) {
408410
var err = e instanceof Error ? e : new Error(e.toString());
409-
err.code = consts.Errors.EBADMSG;
411+
(<any>err).code = consts.Errors.EBADMSG;
410412
callback(err);
411413
}
412414
}

Node/core/src/bots/Library.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Library {
8888
l = this.libraries[lib];
8989
} else {
9090
// Search for lib
91-
for (name in this.libraries) {
91+
for (var name in this.libraries) {
9292
l = this.libraries[name].library(lib);
9393
if (l) {
9494
break;

Node/core/src/dialogs/EntityRecognizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class EntityRecognizer {
257257
}
258258
return list;
259259
} else {
260-
return [choices.toString()];
260+
return [(<string>choices).toString()];
261261
}
262262
}
263263
}

Node/core/src/dialogs/IntentDialog.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ export class IntentDialog extends dlg.Dialog {
261261
if (!err) {
262262
done(null, result);
263263
} else {
264-
done(err instanceof Error ? err : new Error(err.toString()), null);
264+
var m = err.toString();
265+
done(err instanceof Error ? err : new Error(m), null);
265266
}
266267
});
267268
}
@@ -314,7 +315,8 @@ export class IntentDialog extends dlg.Dialog {
314315
}
315316

316317
private emitError(session: ses.Session, err: Error): void {
317-
err = err instanceof Error ? err : new Error(err.toString());
318+
var m = err.toString();
319+
err = err instanceof Error ? err : new Error(m);
318320
session.error(err);
319321
}
320322
}

Node/core/src/dialogs/LuisRecognizer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ export class LuisRecognizer implements intent.IIntentRecognizer {
132132
if (!err) {
133133
callback(null, result.intents, result.entities);
134134
} else {
135-
callback(err instanceof Error ? err : new Error(err.toString()));
135+
var m = err.toString();
136+
callback(err instanceof Error ? err : new Error(m));
136137
}
137138
} catch (e) {
138139
console.error(e.toString());

Node/core/src/dialogs/Prompts.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,7 @@ export class Prompts extends dlg.Dialog {
276276
}
277277

278278
var locale:string = session.preferredLocale();
279-
logger.debug("prompts::preferred locale %s", locale);
280-
if (!locale && session.localizer) {
281-
locale = session.localizer.defaultLocale();
282-
logger.debug("prompts::sendPrompt using default locale %s", locale);
283-
}
284279
prompt = session.localizer.gettext(locale, prompt, args.localizationNamespace);
285-
logger.debug("prompts::sendPrompt localized prompt %s", prompt);
286280

287281

288282
// Append list
@@ -358,10 +352,14 @@ export class Prompts extends dlg.Dialog {
358352
}
359353

360354
static confirm(session: ses.Session, prompt: string|string[]|IMessage|IIsMessage, options?: IPromptOptions): void {
355+
var locale:string = session.preferredLocale();
361356
var args: IPromptArgs = <any>options || {};
362357
args.promptType = PromptType.confirm;
363358
args.prompt = prompt;
364-
args.enumValues = ['confirm_yes','confirm_no'];
359+
args.enumValues = [
360+
session.localizer.gettext(locale, 'confirm_yes', consts.Library.system),
361+
session.localizer.gettext(locale, 'confirm_no', consts.Library.system)
362+
];
365363
args.listStyle = args.hasOwnProperty('listStyle') ? args.listStyle : ListStyle.auto;
366364
beginPrompt(session, args);
367365
}

Node/core/src/locale/en/BotBuilder.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"confirm_no": "no",
99
"default_choice": "I didn't understand. Please choose an option from the list.",
1010
"default_time": "I didn't recognize the time you entered. Please try again.",
11-
"default_file": "I didn't receive a file. Please try again."
11+
"default_file": "I didn't receive a file. Please try again.",
12+
"default_error": "Oops. Something went wrong and we need to start over."
1213
}

0 commit comments

Comments
 (0)