Skip to content

Commit 29258ad

Browse files
jtpiobrichet
andcommitted
address review comments
Co-Authored-By: Nicolas Brichet <brichet@users.noreply.github.com>
1 parent eb7894f commit 29258ad

File tree

10 files changed

+50
-27
lines changed

10 files changed

+50
-27
lines changed

packages/jupyter-chat/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createContext, useContext } from 'react';
88

99
import { Chat } from './components';
1010

11-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
11+
export const TRANSLATION_DOMAIN = 'jupyter-chat';
1212

1313
export const ChatReactContext = createContext<Chat.IChatProps | undefined>(
1414
undefined

packages/jupyter-chat/src/model.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
*/
55

66
import { IDocumentManager } from '@jupyterlab/docmanager';
7+
import {
8+
ITranslator,
9+
nullTranslator,
10+
TranslationBundle
11+
} from '@jupyterlab/translation';
712
import { ArrayExt } from '@lumino/algorithm';
813
import { CommandRegistry } from '@lumino/commands';
914
import { PromiseDelegate } from '@lumino/coreutils';
1015
import { IDisposable } from '@lumino/disposable';
1116
import { ISignal, Signal } from '@lumino/signaling';
1217

1318
import { IActiveCellManager } from './active-cell-manager';
19+
import { TRANSLATION_DOMAIN } from './context';
1420
import { IInputModel, InputModel } from './input-model';
1521
import { Message } from './message';
1622
import { ISelectionWatcher } from './selection-watcher';
@@ -237,6 +243,10 @@ export abstract class AbstractChatModel implements IChatModel {
237243
...config
238244
};
239245

246+
this._trans = (options.translator ?? nullTranslator).load(
247+
TRANSLATION_DOMAIN
248+
);
249+
240250
this._inputModel = new InputModel({
241251
activeCellManager: options.activeCellManager,
242252
selectionWatcher: options.selectionWatcher,
@@ -695,14 +705,24 @@ export abstract class AbstractChatModel implements IChatModel {
695705
this._commands
696706
.execute('apputils:update-notification', {
697707
id: this._notificationId,
698-
message: `${unreadCount} incoming message(s) ${this._name ? 'in ' + this._name : ''}`
708+
message: this._name
709+
? this._trans.__(
710+
'%1 incoming message(s) in %2',
711+
unreadCount,
712+
this._name
713+
)
714+
: this._trans.__('%1 incoming message(s)', unreadCount)
699715
})
700716
.then(success => {
701717
// Create a new notification only if messages are added.
702718
if (!success && canCreate) {
703719
this._commands!.execute('apputils:notify', {
704720
type: 'info',
705-
message: `${unreadCount} incoming message(s) in ${this._name}`
721+
message: this._trans.__(
722+
'%1 incoming message(s) in %2',
723+
unreadCount,
724+
this._name
725+
)
706726
}).then(id => {
707727
this._notificationId = id;
708728
});
@@ -725,6 +745,7 @@ export abstract class AbstractChatModel implements IChatModel {
725745
private _id: string | undefined;
726746
private _name: string = '';
727747
private _config: IConfig;
748+
protected _trans: TranslationBundle;
728749
private _readyDelegate = new PromiseDelegate<void>();
729750
private _inputModel: IInputModel;
730751
private _disposed = new Signal<this, void>(this);
@@ -770,6 +791,11 @@ export namespace IChatModel {
770791
*/
771792
commands?: CommandRegistry;
772793

794+
/**
795+
* The translator for internationalization.
796+
*/
797+
translator?: ITranslator;
798+
773799
/**
774800
* Active cell manager.
775801
*/

packages/jupyter-chat/src/widgets/chat-error.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import { Alert, Box } from '@mui/material';
99
import React from 'react';
1010

1111
import { JlThemeProvider } from '../components/jl-theme-provider';
12+
import { TRANSLATION_DOMAIN } from '../context';
1213
import { chatIcon } from '../icons';
1314

14-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
15-
1615
export function buildErrorWidget(
1716
themeManager: IThemeManager | null,
1817
translator?: ITranslator

packages/jupyter-chat/src/widgets/chat-selector-popup.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
*/
55

66
import { Button } from '@jupyter/react-components';
7-
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
7+
import {
8+
ITranslator,
9+
nullTranslator,
10+
TranslationBundle
11+
} from '@jupyterlab/translation';
812
import { closeIcon, ReactWidget } from '@jupyterlab/ui-components';
913
import { Message } from '@lumino/messaging';
1014
import React, { useEffect, useRef } from 'react';
1115

16+
import { TRANSLATION_DOMAIN } from '../context';
17+
1218
const POPUP_CLASS = 'jp-chat-selector-popup';
1319
const POPUP_LIST_CLASS = 'jp-chat-selector-popup-list';
1420
const POPUP_ITEM_CLASS = 'jp-chat-selector-popup-item';
1521
const POPUP_ITEM_ACTIVE_CLASS = 'jp-chat-selector-popup-item-active';
1622
const POPUP_ITEM_LABEL_CLASS = 'jp-chat-selector-popup-item-label';
1723
const POPUP_EMPTY_CLASS = 'jp-chat-selector-popup-empty';
1824

19-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
20-
2125
/**
2226
* A popup widget for selecting a chat from a filtered list.
2327
*/
@@ -357,9 +361,6 @@ export namespace ChatSelectorPopup {
357361
}
358362
}
359363

360-
// Re-export the ITranslator type for use in the namespace
361-
import { ITranslator } from '@jupyterlab/translation';
362-
363364
/**
364365
* Props for the ChatSelectorList component.
365366
*/

packages/jupyter-chat/src/widgets/chat-sidebar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import { nullTranslator } from '@jupyterlab/translation';
77

88
import { Chat } from '../components/chat';
9+
import { TRANSLATION_DOMAIN } from '../context';
910
import { chatIcon } from '../icons';
1011
import { ChatWidget } from './chat-widget';
1112

12-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
13-
1413
export function buildChatSidebar(options: Chat.IOptions): ChatWidget {
1514
const widget = new ChatWidget(options);
1615
const trans = (options.translator ?? nullTranslator).load(TRANSLATION_DOMAIN);

packages/jupyter-chat/src/widgets/chat-widget.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Drag } from '@lumino/dragdrop';
1515
import { Widget } from '@lumino/widgets';
1616

1717
import { Chat, IInputToolbarRegistry, MESSAGE_CLASS } from '../components';
18+
import { TRANSLATION_DOMAIN } from '../context';
1819
import { chatIcon } from '../icons';
1920
import { IChatModel } from '../model';
2021
import {
@@ -26,8 +27,6 @@ import {
2627
import { ActiveCellManager } from '../active-cell-manager';
2728
import { IInputModel } from '../input-model';
2829

29-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
30-
3130
// MIME type constant for file browser drag events
3231
const FILE_BROWSER_MIME = 'application/x-jupyter-icontentsrich';
3332

packages/jupyter-chat/src/widgets/multichat-panel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
IInputToolbarRegistry,
3434
IInputToolbarRegistryFactory
3535
} from '../components';
36+
import { TRANSLATION_DOMAIN } from '../context';
3637
import { chatIcon, readIcon } from '../icons';
3738
import { IChatModel } from '../model';
3839

@@ -42,8 +43,6 @@ const OPEN_SELECT_CLASS = 'jp-chat-open';
4243
const SIDEPANEL_WIDGET_CLASS = 'jp-chat-sidepanel-widget';
4344
const TOOLBAR_CLASS = 'jp-chat-sidepanel-widget-toolbar';
4445

45-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
46-
4746
/**
4847
* Generic sidepanel widget including multiple chats and the add chat button.
4948
*/

packages/jupyterlab-chat-extension/src/chat-commands/providers/emoji.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ import {
1313
IChatCommandProvider,
1414
IChatCommandRegistry,
1515
ChatCommand,
16-
IInputModel
16+
IInputModel,
17+
TRANSLATION_DOMAIN
1718
} from '@jupyter/chat';
1819

19-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
20-
2120
export class EmojiCommandProvider implements IChatCommandProvider {
2221
constructor(translator?: ITranslator) {
2322
const trans = (translator ?? nullTranslator).load(TRANSLATION_DOMAIN);

packages/jupyterlab-chat-extension/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
MessageFooterRegistry,
2121
MessagePreambleRegistry,
2222
SelectionWatcher,
23+
TRANSLATION_DOMAIN,
2324
chatIcon,
2425
readIcon,
2526
IInputToolbarRegistryFactory,
@@ -75,7 +76,6 @@ import { mentionCommandsPlugin } from './chat-commands/providers/user-mention';
7576

7677
const FACTORY = 'Chat';
7778
const CHAT_LIST_UPDATE_INTERVAL = 2000;
78-
const TRANSLATION_DOMAIN = 'jupyterlab_chat';
7979

8080
const pluginIds = {
8181
activeCellManager: 'jupyterlab-chat-extension:activeCellManager',
@@ -360,6 +360,7 @@ const docFactories: JupyterFrontEndPlugin<ChatWidgetFactory> = {
360360
user,
361361
widgetConfig,
362362
commands: app.commands,
363+
translator,
363364
activeCellManager,
364365
selectionWatcher,
365366
documentManager: filebrowser?.model.manager

packages/jupyterlab-chat/src/model.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ export class LabChatModel
417417
const msg: IMessageContent = {
418418
...baseMessage,
419419
sender: this.sharedModel.getUser(sender) || {
420-
username: 'User undefined',
421-
mention_name: 'User-undefined'
420+
username: this._trans.__('User undefined'),
421+
mention_name: this._trans.__('User-undefined')
422422
}
423423
};
424424

@@ -439,8 +439,8 @@ export class LabChatModel
439439
const mentions: IUser[] = (mentionsIds ?? []).map(
440440
user =>
441441
this.sharedModel.getUser(user) || {
442-
username: 'User undefined',
443-
mention_name: 'User-undefined'
442+
username: this._trans.__('User undefined'),
443+
mention_name: this._trans.__('User-undefined')
444444
}
445445
);
446446

@@ -483,8 +483,8 @@ export class LabChatModel
483483
const mentions: IUser[] = (value as string[]).map(
484484
user =>
485485
this.sharedModel.getUser(user) || {
486-
username: 'User undefined',
487-
mention_name: 'User-undefined'
486+
username: this._trans.__('User undefined'),
487+
mention_name: this._trans.__('User-undefined')
488488
}
489489
);
490490
if (mentions?.length) {

0 commit comments

Comments
 (0)