Merge pull request #229 from jtpio/translation

Add support for translation
pull/6294/head
Jeremy Tuloup 4 years ago committed by GitHub
commit 6ef6d1faab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -141,6 +141,7 @@ async function main() {
require('@jupyterlab/terminal-extension'),
require('@jupyterlab/theme-light-extension'),
require('@jupyterlab/theme-dark-extension'),
require('@jupyterlab/translation-extension'),
// Add the "Hub Control Panel" menu option when running in JupyterHub
require('@jupyterlab/hub-extension')
];

@ -62,6 +62,8 @@
"@jupyterlab/theme-light-extension": "~3.1.11",
"@jupyterlab/tooltip": "~3.1.11",
"@jupyterlab/tooltip-extension": "~3.1.11",
"@jupyterlab/translation": "~3.1.11",
"@jupyterlab/translation-extension": "~3.1.11",
"@jupyterlab/ui-components": "~3.1.11",
"@jupyterlab/vega5-extension": "~3.1.12",
"@lumino/algorithm": "~1.6.0",
@ -115,6 +117,7 @@
"@jupyterlab/theme-dark-extension": "^3.1.11",
"@jupyterlab/theme-light-extension": "^3.1.11",
"@jupyterlab/tooltip-extension": "^3.1.11",
"@jupyterlab/translation-extension": "^3.1.11",
"@jupyterlab/vega5-extension": "^3.1.12",
"@retrolab/application": "^0.3.6",
"@retrolab/application-extension": "^0.3.6",
@ -178,7 +181,8 @@
"@jupyterlab/terminal-extension",
"@jupyterlab/theme-dark-extension",
"@jupyterlab/theme-light-extension",
"@jupyterlab/tooltip-extension"
"@jupyterlab/tooltip-extension",
"@jupyterlab/translation-extension"
],
"singletonPackages": [
"@jupyterlab/application",
@ -205,6 +209,7 @@
"@jupyterlab/statusbar",
"@jupyterlab/terminal",
"@jupyterlab/tooltip",
"@jupyterlab/translation",
"@jupyterlab/ui-components",
"@lumino/algorithm",
"@lumino/application",

@ -4,8 +4,10 @@ channels:
dependencies:
- ipywidgets=7.6
- jupyterlab=3
- jupyterlab-language-pack-fr-FR
- jupyterlab-link-share>=0.2
- matplotlib
- numpy
- nodejs
- python >=3.9,<3.10
- xeus-python

@ -27,7 +27,7 @@ import { DocumentWidget } from '@jupyterlab/docregistry';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { ITranslator, TranslationManager } from '@jupyterlab/translation';
import { ITranslator } from '@jupyterlab/translation';
import { RetroApp, RetroShell, IRetroShell } from '@retrolab/application';
@ -99,7 +99,7 @@ const dirty: JupyterFrontEndPlugin<void> = {
if (!(app instanceof RetroApp)) {
throw new Error(`${dirty.id} must be activated in RetroLab.`);
}
const trans = translator.load('jupyterlab');
const trans = translator.load('retrolab');
const message = trans.__(
'Are you sure you want to exit RetroLab?\n\nAny unsaved changes will be lost.'
);
@ -203,23 +203,26 @@ const noTabsMenu: JupyterFrontEndPlugin<void> = {
const pages: JupyterFrontEndPlugin<void> = {
id: '@retrolab/application-extension:pages',
autoStart: true,
requires: [ITranslator],
optional: [ICommandPalette, IMainMenu],
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
menu: IMainMenu
translator: ITranslator,
palette: ICommandPalette | null,
menu: IMainMenu | null
): void => {
const trans = translator.load('retrolab');
const baseUrl = PageConfig.getBaseUrl();
app.commands.addCommand(CommandIDs.openLab, {
label: 'Open JupyterLab',
label: trans.__('Open JupyterLab'),
execute: () => {
window.open(`${baseUrl}lab`);
}
});
app.commands.addCommand(CommandIDs.openTree, {
label: 'Open Files',
label: trans.__('Open Files'),
execute: () => {
window.open(`${baseUrl}retro/tree`);
}
@ -447,17 +450,19 @@ const title: JupyterFrontEndPlugin<void> = {
*/
const topVisibility: JupyterFrontEndPlugin<void> = {
id: '@retrolab/application-extension:top',
requires: [IRetroShell],
requires: [IRetroShell, ITranslator],
optional: [IMainMenu],
activate: (
app: JupyterFrontEnd<JupyterFrontEnd.IShell>,
retroShell: IRetroShell,
translator: ITranslator,
menu: IMainMenu | null
) => {
const trans = translator.load('retrolab');
const top = retroShell.top;
app.commands.addCommand(CommandIDs.toggleTop, {
label: 'Show Header',
label: trans.__('Show Header'),
execute: () => {
top.setHidden(top.isVisible);
},
@ -483,19 +488,6 @@ const topVisibility: JupyterFrontEndPlugin<void> = {
autoStart: true
};
/**
* A simplified Translator
*/
const translator: JupyterFrontEndPlugin<ITranslator> = {
id: '@retrolab/application-extension:translator',
activate: (app: JupyterFrontEnd<JupyterFrontEnd.IShell>): ITranslator => {
const translationManager = new TranslationManager();
return translationManager;
},
autoStart: true,
provides: ITranslator
};
/**
* The default tree route resolver plugin.
*/
@ -587,15 +579,18 @@ const treePathUpdater: JupyterFrontEndPlugin<ITreePathUpdater> = {
const zen: JupyterFrontEndPlugin<void> = {
id: '@retrolab/application-extension:zen',
autoStart: true,
requires: [ITranslator],
optional: [ICommandPalette, IRetroShell, IMainMenu],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
palette: ICommandPalette | null,
retroShell: IRetroShell | null,
menu: IMainMenu | null
): void => {
const { commands } = app;
const elem = document.documentElement;
const trans = translator.load('retrolab');
const toggleOn = () => {
retroShell?.collapseTop();
@ -611,7 +606,7 @@ const zen: JupyterFrontEndPlugin<void> = {
let zenModeEnabled = false;
commands.addCommand(CommandIDs.toggleZen, {
label: 'Toggle Zen Mode',
label: trans.__('Toggle Zen Mode'),
execute: () => {
if (!zenModeEnabled) {
elem.requestFullscreen();
@ -657,7 +652,6 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
tabTitle,
title,
topVisibility,
translator,
tree,
treePathUpdater,
zen

@ -42,6 +42,7 @@
"@jupyterlab/application": "^3.1.11",
"@jupyterlab/apputils": "^3.1.11",
"@jupyterlab/mainmenu": "^3.1.11",
"@jupyterlab/translation": "^3.1.11",
"@retrolab/ui-components": "^0.3.6"
},
"devDependencies": {

@ -10,6 +10,8 @@ import { showDialog, Dialog } from '@jupyterlab/apputils';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { ITranslator } from '@jupyterlab/translation';
import { retroIcon } from '@retrolab/ui-components';
import * as React from 'react';
@ -45,9 +47,15 @@ namespace CommandIDs {
const plugin: JupyterFrontEndPlugin<void> = {
id: '@retrolab/help-extension:plugin',
autoStart: true,
requires: [ITranslator],
optional: [IMainMenu],
activate: (app: JupyterFrontEnd, menu: IMainMenu): void => {
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
menu: IMainMenu | null
): void => {
const { commands } = app;
const trans = translator.load('retrolab');
commands.addCommand(CommandIDs.open, {
label: args => args['text'] as string,
@ -58,12 +66,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
commands.addCommand(CommandIDs.shortcuts, {
label: 'Keyboard Shortcuts',
label: trans.__('Keyboard Shortcuts'),
execute: () => {
const title = (
<span className="jp-AboutRetro-about-header">
<div className="jp-AboutRetro-about-header-info">
Keyboard Shortcuts
{trans.__('Keyboard Shortcuts')}
</div>
</span>
);
@ -72,8 +80,8 @@ const plugin: JupyterFrontEndPlugin<void> = {
<table className="jp-AboutRetro-shortcuts">
<thead>
<tr>
<th>Name</th>
<th>Shortcut</th>
<th>{trans.__('Name')}</th>
<th>{trans.__('Shortcut')}</th>
</tr>
</thead>
<tbody>
@ -96,7 +104,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
body,
buttons: [
Dialog.createButton({
label: 'Dismiss',
label: trans.__('Dismiss'),
className:
'jp-AboutRetro-about-button jp-mod-reject jp-mod-styled'
})
@ -106,7 +114,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
commands.addCommand(CommandIDs.about, {
label: `About ${app.name}`,
label: trans.__('About %1', app.name),
execute: () => {
const title = (
<>
@ -157,9 +165,11 @@ const plugin: JupyterFrontEndPlugin<void> = {
command: CommandIDs.open
}));
menu.helpMenu.addGroup([{ command: CommandIDs.about }]);
menu.helpMenu.addGroup([{ command: CommandIDs.shortcuts }]);
menu.helpMenu.addGroup(resourcesGroup);
if (menu) {
menu.helpMenu.addGroup([{ command: CommandIDs.about }]);
menu.helpMenu.addGroup([{ command: CommandIDs.shortcuts }]);
menu.helpMenu.addGroup(resourcesGroup);
}
}
};

@ -66,6 +66,7 @@ interface ISwitcherChoice {
const launchButtons: JupyterFrontEndPlugin<void> = {
id: '@retrolab/lab-extension:interface-switcher',
autoStart: true,
requires: [ITranslator],
optional: [
INotebookTracker,
ICommandPalette,
@ -75,6 +76,7 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
notebookTracker: INotebookTracker | null,
palette: ICommandPalette | null,
menu: IMainMenu | null,
@ -88,6 +90,7 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
const { commands, shell } = app;
const baseUrl = PageConfig.getBaseUrl();
const trans = translator.load('retrolab');
const isEnabled = () => {
return (
@ -140,7 +143,7 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
// always add Classic
addInterface({
command: 'retrolab:open-classic',
commandLabel: 'Open in Classic Notebook',
commandLabel: trans.__('Open With %1', 'Classic Notebook'),
buttonLabel: 'openClassic',
icon: jupyterIcon,
urlPrefix: `${baseUrl}tree/`
@ -149,7 +152,7 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
if (!retroShell) {
addInterface({
command: 'retrolab:open-retro',
commandLabel: 'Open in RetroLab',
commandLabel: trans.__('Open With %1', 'RetroLab'),
buttonLabel: 'openRetro',
icon: retroSunIcon,
urlPrefix: `${baseUrl}retro/tree/`
@ -159,7 +162,7 @@ const launchButtons: JupyterFrontEndPlugin<void> = {
if (!labShell) {
addInterface({
command: 'retrolab:open-lab',
commandLabel: 'Open in JupyterLab',
commandLabel: trans.__('Open With %1', 'JupyterLab'),
buttonLabel: 'openLab',
icon: jupyterFaviconIcon,
urlPrefix: `${baseUrl}doc/tree/`
@ -183,7 +186,7 @@ const launchRetroTree: JupyterFrontEndPlugin<void> = {
palette: ICommandPalette | null
): void => {
const { commands } = app;
const trans = translator.load('jupyterlab');
const trans = translator.load('retrolab');
const category = trans.__('Help');
commands.addCommand(CommandIDs.launchRetroTree, {

@ -43,6 +43,7 @@
"@jupyterlab/apputils": "^3.1.11",
"@jupyterlab/docmanager": "^3.1.11",
"@jupyterlab/notebook": "^3.1.11",
"@jupyterlab/translation": "^3.1.11",
"@lumino/polling": "^1.6.0",
"@lumino/widgets": "^1.23.0",
"@retrolab/application": "^0.3.6"

@ -14,6 +14,8 @@ import { IDocumentManager } from '@jupyterlab/docmanager';
import { NotebookPanel } from '@jupyterlab/notebook';
import { ITranslator } from '@jupyterlab/translation';
import { RetroApp, RetroShell, IRetroShell } from '@retrolab/application';
import { Poll } from '@lumino/polling';
@ -46,14 +48,16 @@ const KERNEL_STATUS_FADE_OUT_CLASS = 'jp-RetroKernelStatus-fade';
const checkpoints: JupyterFrontEndPlugin<void> = {
id: '@retrolab/application-extension:checkpoints',
autoStart: true,
requires: [IDocumentManager],
requires: [IDocumentManager, ITranslator],
optional: [IRetroShell],
activate: (
app: JupyterFrontEnd,
docManager: IDocumentManager,
retroShell: IRetroShell
translator: ITranslator,
retroShell: IRetroShell | null
) => {
const { shell } = app;
const trans = translator.load('retrolab');
const widget = new Widget();
widget.id = DOMUtils.createDomID();
widget.addClass('jp-RetroCheckpoint');
@ -74,9 +78,10 @@ const checkpoints: JupyterFrontEndPlugin<void> = {
return;
}
const checkpoint = checkpoints[checkpoints.length - 1];
widget.node.textContent = `Last Checkpoint: ${Time.formatHuman(
new Date(checkpoint.last_modified)
)}`;
widget.node.textContent = trans.__(
'Last Checkpoint: %1',
Time.formatHuman(new Date(checkpoint.last_modified))
);
};
if (retroShell) {

@ -27,16 +27,21 @@ import { TabPanel } from '@lumino/widgets';
*/
const newFiles: JupyterFrontEndPlugin<void> = {
id: '@retrolab/tree-extension:buttons',
requires: [IFileBrowserFactory],
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (app: JupyterFrontEnd, filebrowser: IFileBrowserFactory) => {
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('retrolab');
// wrapper commands to be able to override the label
const newNotebookCommand = 'tree:new-notebook';
commands.addCommand(newNotebookCommand, {
label: 'New Notebook',
label: trans.__('New Notebook'),
icon: notebookIcon,
execute: () => {
return commands.execute('notebook:create-new');
@ -63,15 +68,20 @@ const newFiles: JupyterFrontEndPlugin<void> = {
*/
const newConsole: JupyterFrontEndPlugin<void> = {
id: '@retrolab/tree-extension:new-console',
requires: [IFileBrowserFactory],
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (app: JupyterFrontEnd, filebrowser: IFileBrowserFactory) => {
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('retrolab');
const newConsoleCommand = 'tree:new-console';
commands.addCommand(newConsoleCommand, {
label: 'New Console',
label: trans.__('New Console'),
icon: consoleIcon,
execute: () => {
return commands.execute('console:create');
@ -92,15 +102,20 @@ const newConsole: JupyterFrontEndPlugin<void> = {
*/
const newTerminal: JupyterFrontEndPlugin<void> = {
id: '@retrolab/tree-extension:new-terminal',
requires: [IFileBrowserFactory],
requires: [IFileBrowserFactory, ITranslator],
autoStart: true,
activate: (app: JupyterFrontEnd, filebrowser: IFileBrowserFactory) => {
activate: (
app: JupyterFrontEnd,
filebrowser: IFileBrowserFactory,
translator: ITranslator
) => {
const { commands } = app;
const browser = filebrowser.defaultBrowser;
const trans = translator.load('retrolab');
const newTerminalCommand = 'tree:new-terminal';
commands.addCommand(newTerminalCommand, {
label: 'New Terminal',
label: trans.__('New Terminal'),
icon: terminalIcon,
execute: () => {
return commands.execute('terminal:create-new');
@ -133,15 +148,17 @@ const browserWidget: JupyterFrontEndPlugin<void> = {
const tabPanel = new TabPanel({ tabPlacement: 'top', tabsMovable: true });
tabPanel.addClass('jp-TreePanel');
const trans = translator.load('retrolab');
const { defaultBrowser: browser } = factory;
browser.title.label = 'Files';
browser.title.label = trans.__('Files');
tabPanel.addWidget(browser);
tabPanel.tabBar.addTab(browser.title);
if (manager) {
const running = new RunningSessions(manager, translator);
running.id = 'jp-running-sessions';
running.title.label = 'Running';
running.title.label = trans.__('Running');
running.title.icon = runningIcon;
tabPanel.addWidget(running);
tabPanel.tabBar.addTab(running.title);

@ -2570,6 +2570,17 @@
"@lumino/messaging" "^1.4.3"
"@lumino/widgets" "^1.19.0"
"@jupyterlab/translation-extension@^3.1.11":
version "3.1.11"
resolved "https://registry.yarnpkg.com/@jupyterlab/translation-extension/-/translation-extension-3.1.11.tgz#62deaf4e7a75282258c6a4fd82bb7e3638892a4d"
integrity sha512-FrdH1x0DpYz45T6r/z5bGlOc/JgMQEdpRk1j3HmJUZyoh7aQcc9dNCzfnj7gpeNRL2aMqRKdsOiBXecKuun2hg==
dependencies:
"@jupyterlab/application" "^3.1.11"
"@jupyterlab/apputils" "^3.1.11"
"@jupyterlab/mainmenu" "^3.1.11"
"@jupyterlab/settingregistry" "^3.1.11"
"@jupyterlab/translation" "^3.1.11"
"@jupyterlab/translation@^3.1.11":
version "3.1.11"
resolved "https://registry.yarnpkg.com/@jupyterlab/translation/-/translation-3.1.11.tgz#b3158d813c0779324f8dd5aa2b1c7fd6ffcbcfef"

Loading…
Cancel
Save