Skip to content

Commit 5b0ccfc

Browse files
jtpiobrichet
andauthored
Localize user facing strings (#380)
* Localize user facing strings * address review comments Co-Authored-By: Nicolas Brichet <brichet@users.noreply.github.com> --------- Co-authored-by: Nicolas Brichet <brichet@users.noreply.github.com>
1 parent 123c948 commit 5b0ccfc

File tree

27 files changed

+318
-140
lines changed

27 files changed

+318
-140
lines changed

packages/jupyter-chat/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@jupyterlab/fileeditor": "^4.2.0",
5757
"@jupyterlab/notebook": "^4.2.0",
5858
"@jupyterlab/rendermime": "^4.2.0",
59+
"@jupyterlab/translation": "^4.2.0",
5960
"@jupyterlab/ui-components": "^4.2.0",
6061
"@lumino/algorithm": "^2.0.0",
6162
"@lumino/commands": "^2.0.0",

packages/jupyter-chat/src/components/attachments.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PathExt } from '@jupyterlab/coreutils';
1010
import { UUID } from '@lumino/coreutils';
1111

1212
import { TooltippedIconButton } from './mui-extras';
13-
import { useChatContext } from '../context';
13+
import { useChatContext, useTranslator } from '../context';
1414
import { IAttachment } from '../types';
1515

1616
const ATTACHMENT_CLASS = 'jp-chat-attachment';
@@ -87,7 +87,7 @@ export type AttachmentProps = AttachmentsProps & {
8787
* The Attachment component.
8888
*/
8989
export function AttachmentPreview(props: AttachmentProps): JSX.Element {
90-
const remove_tooltip = 'Remove attachment';
90+
const trans = useTranslator();
9191
const { attachmentOpenerRegistry } = useChatContext();
9292
const isClickable = !!attachmentOpenerRegistry?.get(props.attachment.type);
9393

@@ -133,7 +133,7 @@ export function AttachmentPreview(props: AttachmentProps): JSX.Element {
133133
</Tooltip>
134134
{props.onRemove && (
135135
<TooltippedIconButton
136-
tooltip={remove_tooltip}
136+
tooltip={trans.__('Remove attachment')}
137137
onClick={() => props.onRemove!(props.attachment)}
138138
className={REMOVE_BUTTON_CLASS}
139139
inputToolbar={false}

packages/jupyter-chat/src/components/chat.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { IThemeManager } from '@jupyterlab/apputils';
77
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
8+
import { ITranslator } from '@jupyterlab/translation';
89
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
910
import SettingsIcon from '@mui/icons-material/Settings';
1011
import { IconButton } from '@mui/material';
@@ -181,6 +182,10 @@ export namespace Chat {
181182
* The area where the chat is displayed.
182183
*/
183184
area?: ChatArea;
185+
/**
186+
* The translator for internationalization.
187+
*/
188+
translator?: ITranslator;
184189
}
185190

186191
/**

packages/jupyter-chat/src/components/code-blocks/code-toolbar.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React, { useEffect, useState } from 'react';
99

1010
import { CopyButton } from './copy-button';
1111
import { TooltippedIconButton } from '../mui-extras';
12+
import { useTranslator } from '../../context';
1213
import { IActiveCellManager } from '../../active-cell-manager';
1314
import { replaceCellIcon } from '../../icons';
1415
import { IChatModel } from '../../model';
@@ -110,9 +111,10 @@ type ToolbarButtonProps = {
110111
};
111112

112113
function InsertAboveButton(props: ToolbarButtonProps) {
114+
const trans = useTranslator();
113115
const tooltip = props.activeCellAvailable
114-
? 'Insert above active cell'
115-
: 'Insert above active cell (no active cell)';
116+
? trans.__('Insert above active cell')
117+
: trans.__('Insert above active cell (no active cell)');
116118

117119
return (
118120
<TooltippedIconButton
@@ -128,9 +130,10 @@ function InsertAboveButton(props: ToolbarButtonProps) {
128130
}
129131

130132
function InsertBelowButton(props: ToolbarButtonProps) {
133+
const trans = useTranslator();
131134
const tooltip = props.activeCellAvailable
132-
? 'Insert below active cell'
133-
: 'Insert below active cell (no active cell)';
135+
? trans.__('Insert below active cell')
136+
: trans.__('Insert below active cell (no active cell)');
134137

135138
return (
136139
<TooltippedIconButton
@@ -146,11 +149,15 @@ function InsertBelowButton(props: ToolbarButtonProps) {
146149
}
147150

148151
function ReplaceButton(props: ToolbarButtonProps) {
152+
const trans = useTranslator();
149153
const tooltip = props.selectionExists
150-
? `Replace selection (${props.selectionWatcher?.selection?.numLines} line(s))`
154+
? trans.__(
155+
'Replace selection (%1 line(s))',
156+
props.selectionWatcher?.selection?.numLines ?? 0
157+
)
151158
: props.activeCellAvailable
152-
? 'Replace selection (active cell)'
153-
: 'Replace selection (no selection)';
159+
? trans.__('Replace selection (active cell)')
160+
: trans.__('Replace selection (no selection)');
154161

155162
const disabled = !props.activeCellAvailable && !props.selectionExists;
156163

packages/jupyter-chat/src/components/code-blocks/copy-button.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { copyIcon } from '@jupyterlab/ui-components';
77
import React, { useState, useCallback, useRef } from 'react';
88

99
import { TooltippedIconButton } from '../mui-extras';
10+
import { useTranslator } from '../../context';
1011

1112
enum CopyStatus {
1213
None,
@@ -15,19 +16,13 @@ enum CopyStatus {
1516
Disabled
1617
}
1718

18-
const COPYBTN_TEXT_BY_STATUS: Record<CopyStatus, string> = {
19-
[CopyStatus.None]: 'Copy to clipboard',
20-
[CopyStatus.Copying]: 'Copying…',
21-
[CopyStatus.Copied]: 'Copied!',
22-
[CopyStatus.Disabled]: 'Copy to clipboard disabled in insecure context'
23-
};
24-
2519
type CopyButtonProps = {
2620
value: string;
2721
className?: string;
2822
};
2923

3024
export function CopyButton(props: CopyButtonProps): JSX.Element {
25+
const trans = useTranslator();
3126
const isCopyDisabled = navigator.clipboard === undefined;
3227
const [copyStatus, setCopyStatus] = useState<CopyStatus>(
3328
isCopyDisabled ? CopyStatus.Disabled : CopyStatus.None
@@ -58,6 +53,15 @@ export function CopyButton(props: CopyButtonProps): JSX.Element {
5853
);
5954
}, [copyStatus, props.value]);
6055

56+
const COPYBTN_TEXT_BY_STATUS: Record<CopyStatus, string> = {
57+
[CopyStatus.None]: trans.__('Copy to clipboard'),
58+
[CopyStatus.Copying]: trans.__('Copying…'),
59+
[CopyStatus.Copied]: trans.__('Copied!'),
60+
[CopyStatus.Disabled]: trans.__(
61+
'Copy to clipboard disabled in insecure context'
62+
)
63+
};
64+
6165
const tooltip = COPYBTN_TEXT_BY_STATUS[copyStatus];
6266

6367
return (
@@ -67,7 +71,7 @@ export function CopyButton(props: CopyButtonProps): JSX.Element {
6771
tooltip={tooltip}
6872
placement="top"
6973
onClick={copy}
70-
aria-label="Copy to clipboard"
74+
aria-label={trans.__('Copy to clipboard')}
7175
inputToolbar={false}
7276
>
7377
<copyIcon.react height="16px" width="16px" />

packages/jupyter-chat/src/components/input/buttons/attach-button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React from 'react';
99

1010
import { InputToolbarRegistry } from '../toolbar-registry';
1111
import { TooltippedIconButton } from '../../mui-extras';
12+
import { useTranslator } from '../../../context';
1213

1314
const ATTACH_BUTTON_CLASS = 'jp-chat-attach-button';
1415

@@ -19,7 +20,8 @@ export function AttachButton(
1920
props: InputToolbarRegistry.IToolbarItemProps
2021
): JSX.Element {
2122
const { model } = props;
22-
const tooltip = 'Add attachment';
23+
const trans = useTranslator();
24+
const tooltip = trans.__('Add attachment');
2325

2426
if (!model.documentManager || !model.addAttachment) {
2527
return <></>;
@@ -31,7 +33,7 @@ export function AttachButton(
3133
}
3234
try {
3335
const files = await FileDialog.getOpenFiles({
34-
title: 'Select files to attach',
36+
title: trans.__('Select files to attach'),
3537
manager: model.documentManager
3638
});
3739
if (files.value) {

packages/jupyter-chat/src/components/input/buttons/cancel-button.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from 'react';
88

99
import { InputToolbarRegistry } from '../toolbar-registry';
1010
import { TooltippedIconButton } from '../../mui-extras';
11+
import { useTranslator } from '../../../context';
1112

1213
const CANCEL_BUTTON_CLASS = 'jp-chat-cancel-button';
1314

@@ -17,10 +18,12 @@ const CANCEL_BUTTON_CLASS = 'jp-chat-cancel-button';
1718
export function CancelButton(
1819
props: InputToolbarRegistry.IToolbarItemProps
1920
): JSX.Element {
21+
const trans = useTranslator();
22+
2023
if (!props.model.cancel) {
2124
return <></>;
2225
}
23-
const tooltip = 'Cancel editing';
26+
const tooltip = trans.__('Cancel editing');
2427
return (
2528
<TooltippedIconButton
2629
onClick={props.model.cancel}

packages/jupyter-chat/src/components/input/buttons/save-edit-button.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react';
88

99
import { InputToolbarRegistry } from '../toolbar-registry';
1010
import { TooltippedIconButton } from '../../mui-extras';
11+
import { useTranslator } from '../../../context';
1112

1213
const SAVE_EDIT_BUTTON_CLASS = 'jp-chat-save-edit-button';
1314

@@ -18,14 +19,15 @@ export function SaveEditButton(
1819
props: InputToolbarRegistry.IToolbarItemProps
1920
): JSX.Element {
2021
const { model, chatCommandRegistry, edit } = props;
22+
const trans = useTranslator();
2123

2224
// Don't show this button when not in edit mode
2325
if (!edit) {
2426
return <></>;
2527
}
2628

2729
const [disabled, setDisabled] = useState(false);
28-
const tooltip = 'Save edits';
30+
const tooltip = trans.__('Save edits');
2931

3032
useEffect(() => {
3133
const inputChanged = () => {

packages/jupyter-chat/src/components/input/buttons/send-button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react';
88

99
import { InputToolbarRegistry } from '../toolbar-registry';
1010
import { TooltippedIconButton } from '../../mui-extras';
11+
import { useTranslator } from '../../../context';
1112
import { IInputModel, InputModel } from '../../../input-model';
1213

1314
const SEND_BUTTON_CLASS = 'jp-chat-send-button';
@@ -19,6 +20,7 @@ export function SendButton(
1920
props: InputToolbarRegistry.IToolbarItemProps
2021
): JSX.Element {
2122
const { model, chatCommandRegistry, edit } = props;
23+
const trans = useTranslator();
2224

2325
// Don't show this button when in edit mode
2426
if (edit) {
@@ -42,8 +44,8 @@ export function SendButton(
4244
const configChanged = (_: IInputModel, config: InputModel.IConfig) => {
4345
setTooltip(
4446
(config.sendWithShiftEnter ?? false)
45-
? 'Send message (SHIFT+ENTER)'
46-
: 'Send message (ENTER)'
47+
? trans.__('Send message (SHIFT+ENTER)')
48+
: trans.__('Send message (ENTER)')
4749
);
4850
};
4951
model.configChanged.connect(configChanged);

packages/jupyter-chat/src/components/input/buttons/stop-button.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react';
88

99
import { InputToolbarRegistry } from '../toolbar-registry';
1010
import { TooltippedIconButton } from '../../mui-extras';
11+
import { useTranslator } from '../../../context';
1112

1213
const STOP_BUTTON_CLASS = 'jp-chat-stop-button';
1314

@@ -19,7 +20,8 @@ export function StopButton(
1920
): JSX.Element {
2021
const { chatModel } = props;
2122
const [disabled, setDisabled] = useState(true);
22-
const tooltip = 'Stop generating';
23+
const trans = useTranslator();
24+
const tooltip = trans.__('Stop generating');
2325

2426
useEffect(() => {
2527
if (!chatModel) {

0 commit comments

Comments
 (0)