Skip to content

Commit 12ba1ed

Browse files
Add translation to missing items (jupyterlab#1180)
* add translation to Git Clone tooltip * add translation for git menu * add translation to submenu * add phrases object for merge addon translations * Update src/components/diff/PlainTextDiff.ts Change to CodeMirror 5 translations. Co-authored-by: Frédéric Collonval <[email protected]> * Update src/components/diff/PlainTextDiff.ts Change translation to type Record. Co-authored-by: Frédéric Collonval <[email protected]> * Update src/components/diff/PlainTextDiff.ts Change translation to type Record. Co-authored-by: Frédéric Collonval <[email protected]> * Update schema/plugin.json Fix indentation Co-authored-by: Frédéric Collonval <[email protected]> * Update src/components/diff/mergeview.ts Make phrases optional Co-authored-by: Frédéric Collonval <[email protected]> Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 7b233f5 commit 12ba1ed

File tree

7 files changed

+73
-10
lines changed

7 files changed

+73
-10
lines changed

schema/plugin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,11 @@
180180
"rank": 1
181181
}
182182
]
183+
},
184+
"jupyter.lab.internationalization": {
185+
"selectors": [
186+
"jupyter.lab.menus/.*/args/text"
187+
],
188+
"domain": "jupyterlab_git"
183189
}
184190
}

src/cloneCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin<void> = {
8383
}
8484
});
8585
// Add a clone button to the file browser extension toolbar
86-
addCloneButton(gitModel, fileBrowser, app.commands);
86+
addCloneButton(gitModel, fileBrowser, app.commands, trans);
8787

8888
// Add the context menu items for the default file browser
89-
addFileBrowserContextMenu(gitModel, fileBrowser, app.contextMenu);
89+
addFileBrowserContextMenu(gitModel, fileBrowser, app.contextMenu, trans);
9090
},
9191
autoStart: true
9292
};

src/commandsAndMenu.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export function addCommands(
234234

235235
/** Open URL externally */
236236
commands.addCommand(CommandIDs.gitOpenUrl, {
237-
label: args => args['text'] as string,
237+
label: args => trans.__(args['text'] as string),
238238
execute: args => {
239239
const url = args['url'] as string;
240240
window.open(url);
@@ -1300,7 +1300,7 @@ export function createGitMenu(
13001300
];
13011301

13021302
const menu = new Menu({ commands });
1303-
menu.title.label = 'Git';
1303+
menu.title.label = trans.__('Git');
13041304
[
13051305
CommandIDs.gitInit,
13061306
CommandIDs.gitClone,
@@ -1382,7 +1382,8 @@ export function addMenuItems(
13821382
export function addFileBrowserContextMenu(
13831383
model: IGitExtension,
13841384
filebrowser: FileBrowser,
1385-
contextMenu: ContextMenuSvg
1385+
contextMenu: ContextMenuSvg,
1386+
trans: TranslationBundle
13861387
): void {
13871388
let gitMenu: Menu;
13881389
let _commands: ContextCommandIDs[];
@@ -1505,7 +1506,7 @@ export function addFileBrowserContextMenu(
15051506

15061507
const selectorNotDir = '.jp-DirListing-item[data-isdir="false"]';
15071508
gitMenu = new GitMenu({ commands: contextMenu.menu.commands });
1508-
gitMenu.title.label = 'Git';
1509+
gitMenu.title.label = trans.__('Git');
15091510
gitMenu.title.icon = gitIcon.bindprops({ stylesheet: 'menuItem' });
15101511

15111512
contextMenu.addItem({

src/components/diff/PlainTextDiff.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,45 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
4747
this._model = model;
4848
this._trans = translator ?? nullTranslator.load('jupyterlab_git');
4949

50+
// The list of internal strings is available at https://codemirror.net/examples/translate/
51+
this._translations = {
52+
// @codemirror/view
53+
'Control character': this._trans.__('Control character'),
54+
// @codemirror/commands
55+
'Selection deleted': this._trans.__('Selection deleted'),
56+
// @codemirror/language
57+
'Folded lines': this._trans.__('Folded lines'),
58+
'Unfolded lines': this._trans.__('Unfolded lines'),
59+
to: this._trans.__('to'),
60+
'folded code': this._trans.__('folded code'),
61+
unfold: this._trans.__('unfold'),
62+
'Fold line': this._trans.__('Fold line'),
63+
'Unfold line': this._trans.__('Unfold line'),
64+
// @codemirror/search
65+
'Go to line': this._trans.__('Go to line'),
66+
go: this._trans.__('go'),
67+
Find: this._trans.__('Find'),
68+
Replace: this._trans.__('Replace'),
69+
next: this._trans.__('next'),
70+
previous: this._trans.__('previous'),
71+
all: this._trans.__('all'),
72+
'match case': this._trans.__('match case'),
73+
replace: this._trans.__('replace'),
74+
'replace all': this._trans.__('replace all'),
75+
close: this._trans.__('close'),
76+
'current match': this._trans.__('current match'),
77+
'replaced $ matches': this._trans.__('replaced $ matches'),
78+
'replaced match on line $': this._trans.__('replaced match on line $'),
79+
'on line': this._trans.__('on line'),
80+
// From https://codemirror.net/5/addon/merge/merge.js
81+
'Identical text collapsed. Click to expand.': this._trans.__(
82+
'Identical text collapsed. Click to expand.'
83+
),
84+
'Toggle locked scrolling': this._trans.__('Toggle locked scrolling'),
85+
'Push to left': this._trans.__('Push to left'),
86+
'Revert chunk': this._trans.__('Revert chunk')
87+
};
88+
5089
// Load file content early
5190
Promise.all([
5291
this._model.reference.content(),
@@ -124,6 +163,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
124163
this.createDiffView(
125164
this._challenger,
126165
this._reference,
166+
this._translations,
127167
this._hasConflict ? this._base : null
128168
);
129169
}
@@ -166,6 +206,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
166206
this.createDiffView(
167207
this._challenger,
168208
this._reference,
209+
this._translations,
169210
this._hasConflict ? this._base : null
170211
);
171212

@@ -205,6 +246,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
205246
protected async createDiffView(
206247
challengerContent: string,
207248
referenceContent: string,
249+
translations: Record<string, string>,
208250
baseContent?: string
209251
): Promise<void> {
210252
if (!this._mergeView) {
@@ -216,6 +258,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
216258
value: challengerContent,
217259
orig: referenceContent,
218260
mode: mode.mime,
261+
phrases: translations,
219262
...this.getDefaultOptions()
220263
};
221264

@@ -276,6 +319,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
276319
protected _mergeView: MergeView.MergeViewEditor;
277320
protected _model: Git.Diff.IModel;
278321
protected _trans: TranslationBundle;
322+
protected _translations: Record<string, string>;
279323

280324
private _reference: string | null = null;
281325
private _challenger: string | null = null;

src/components/diff/mergeview.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export namespace MergeView {
9090
*/
9191
showDifferences?: boolean;
9292

93+
/**
94+
* Mapping of displayed string with their translation.
95+
*/
96+
phrases?: Record<string, string>;
97+
9398
revertChunk?: (
9499
mergeView: IMergeViewEditor,
95100
from: CodeMirror.Editor,

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,18 @@ async function activate(
201201
}
202202

203203
// Add a clone button to the file browser extension toolbar
204-
addCloneButton(gitExtension, fileBrowser, app.commands);
204+
addCloneButton(gitExtension, fileBrowser, app.commands, trans);
205205

206206
// Add the status bar widget
207207
addStatusBarWidget(statusBar, gitExtension, settings, trans);
208208

209209
// Add the context menu items for the default file browser
210-
addFileBrowserContextMenu(gitExtension, fileBrowser, app.contextMenu);
210+
addFileBrowserContextMenu(
211+
gitExtension,
212+
fileBrowser,
213+
app.contextMenu,
214+
trans
215+
);
211216
}
212217

213218
// Register diff providers

src/widgets/gitClone.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@jupyterlab/apputils';
66
import { IChangedArgs } from '@jupyterlab/coreutils';
77
import { FileBrowser } from '@jupyterlab/filebrowser';
8+
import { TranslationBundle } from '@jupyterlab/translation';
89
import { CommandRegistry } from '@lumino/commands';
910
import * as React from 'react';
1011
import { cloneIcon } from '../style/icons';
@@ -13,7 +14,8 @@ import { CommandIDs, IGitExtension } from '../tokens';
1314
export function addCloneButton(
1415
model: IGitExtension,
1516
filebrowser: FileBrowser,
16-
commands: CommandRegistry
17+
commands: CommandRegistry,
18+
trans: TranslationBundle
1719
): void {
1820
filebrowser.toolbar.addItem(
1921
'gitClone',
@@ -33,7 +35,7 @@ export function addCloneButton(
3335
onClick={() => {
3436
commands.execute(CommandIDs.gitClone);
3537
}}
36-
tooltip={'Git Clone'}
38+
tooltip={trans.__('Git Clone')}
3739
/>
3840
)}
3941
</UseSignal>

0 commit comments

Comments
 (0)