Translating Arduino-IDE using Theia's nls API (#545)

This commit is contained in:
Mark Sujew
2021-10-18 09:59:33 +02:00
committed by GitHub
parent 61262c23ac
commit 11b75bd610
76 changed files with 1445 additions and 499 deletions

View File

@@ -15,6 +15,7 @@ import {
import { Sketch } from '../../../common/protocol';
import { SaveAsSketch } from '../../contributions/save-as-sketch';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class ApplicationShell extends TheiaApplicationShell {
@@ -85,7 +86,10 @@ export class ApplicationShell extends TheiaApplicationShell {
this.connectionStatusService.currentStatus === ConnectionStatus.OFFLINE
) {
this.messageService.error(
'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
nls.localize(
'theia/core/couldNotSave',
'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
)
);
return; // Theia does not reject on failed save: https://github.com/eclipse-theia/theia/pull/8803
}

View File

@@ -8,6 +8,7 @@ import {
} from '@theia/core/lib/browser/connection-status-service';
import { ArduinoDaemon } from '../../../common/protocol';
import { NotificationCenter } from '../../notification-center';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class FrontendConnectionStatusService extends TheiaFrontendConnectionStatusService {
@@ -63,10 +64,19 @@ export class ApplicationConnectionStatusContribution extends TheiaApplicationCon
protected handleOffline(): void {
this.statusBar.setElement('connection-status', {
alignment: StatusBarAlignment.LEFT,
text: this.isRunning ? 'Offline' : '$(bolt) CLI Daemon Offline',
text: this.isRunning
? nls.localize('theia/core/offline', 'Offline')
: '$(bolt) ' +
nls.localize('theia/core/daemonOffline', 'CLI Daemon Offline'),
tooltip: this.isRunning
? 'Cannot connect to the backend.'
: 'Cannot connect to the CLI daemon.',
? nls.localize(
'theia/core/cannotConnectBackend',
'Cannot connect to the backend.'
)
: nls.localize(
'theia/core/cannotConnectDaemon',
'Cannot connect to the CLI daemon.'
),
priority: 5000,
});
this.toDisposeOnOnline.push(

View File

@@ -3,51 +3,63 @@ import { DebugError } from '@theia/debug/lib/common/debug-service';
import { DebugSession } from '@theia/debug/lib/browser/debug-session';
import { DebugSessionOptions } from '@theia/debug/lib/browser/debug-session-options';
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class DebugSessionManager extends TheiaDebugSessionManager {
async start(options: DebugSessionOptions): Promise<DebugSession | undefined> {
return this.progressService.withProgress('Start...', 'debug', async () => {
try {
// Only save when dirty. To avoid saving temporary sketches.
// This is a quick fix for not saving the editor when there are no dirty editors.
// // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
if (this.shell.canSaveAll()) {
await this.shell.saveAll();
}
await this.fireWillStartDebugSession();
const resolved = await this.resolveConfiguration(options);
return this.progressService.withProgress(
nls.localize('theia/debug/start', 'Start...'),
'debug',
async () => {
try {
// Only save when dirty. To avoid saving temporary sketches.
// This is a quick fix for not saving the editor when there are no dirty editors.
// // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888
if (this.shell.canSaveAll()) {
await this.shell.saveAll();
}
await this.fireWillStartDebugSession();
const resolved = await this.resolveConfiguration(options);
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
if (!options.configuration.__restart) {
const taskRun = await this.runTask(
options.workspaceFolderUri,
resolved.configuration.preLaunchTask,
true
// preLaunchTask isn't run in case of auto restart as well as postDebugTask
if (!options.configuration.__restart) {
const taskRun = await this.runTask(
options.workspaceFolderUri,
resolved.configuration.preLaunchTask,
true
);
if (!taskRun) {
return undefined;
}
}
const sessionId = await this.debug.createDebugSession(
resolved.configuration
);
if (!taskRun) {
return this.doStart(sessionId, resolved);
} catch (e) {
if (DebugError.NotFound.is(e)) {
this.messageService.error(
nls.localize(
'theia/debug/typeNotSupported',
'The debug session type "{0}" is not supported.',
e.data.type
)
);
return undefined;
}
}
const sessionId = await this.debug.createDebugSession(
resolved.configuration
);
return this.doStart(sessionId, resolved);
} catch (e) {
if (DebugError.NotFound.is(e)) {
this.messageService.error(
`The debug session type "${e.data.type}" is not supported.`
nls.localize(
'theia/debug/startError',
'There was an error starting the debug session, check the logs for more details.'
)
);
return undefined;
console.error('Error starting the debug session', e);
throw e;
}
this.messageService.error(
'There was an error starting the debug session, check the logs for more details.'
);
console.error('Error starting the debug session', e);
throw e;
}
});
);
}
}

View File

@@ -5,6 +5,7 @@ import { LabelProvider } from '@theia/core/lib/browser';
import { EditorWidgetFactory as TheiaEditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { SketchesService, Sketch } from '../../../common/protocol';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class EditorWidgetFactory extends TheiaEditorWidgetFactory {
@@ -30,7 +31,11 @@ export class EditorWidgetFactory extends TheiaEditorWidgetFactory {
if (sketch && Sketch.isInSketch(uri, sketch)) {
const isTemp = await this.sketchesService.isTemp(sketch);
if (isTemp) {
widget.title.caption = `Unsaved ${this.labelProvider.getName(uri)}`;
widget.title.caption = nls.localize(
'theia/editor/unsavedTitle',
'Unsaved {0}',
this.labelProvider.getName(uri)
);
}
}
return widget;

View File

@@ -5,13 +5,17 @@ import {
KeymapsCommands,
} from '@theia/keymaps/lib/browser/keymaps-frontend-contribution';
import { ArduinoMenus } from '../../menu/arduino-menus';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class KeymapsFrontendContribution extends TheiaKeymapsFrontendContribution {
registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(ArduinoMenus.FILE__ADVANCED_SUBMENU, {
commandId: KeymapsCommands.OPEN_KEYMAPS.id,
label: 'Keyboard Shortcuts',
label: nls.localize(
'vscode/helpActions/miKeyboardShortcuts',
'Keyboard Shortcuts'
),
order: '1',
});
}

View File

@@ -1,13 +1,22 @@
import * as React from 'react';
import { NotificationComponent } from './notification-component';
import { NotificationCenterComponent as TheiaNotificationCenterComponent } from '@theia/messages/lib/browser/notification-center-component';
import { nls } from '@theia/core/lib/browser/nls';
const PerfectScrollbar = require('react-perfect-scrollbar');
export class NotificationCenterComponent extends TheiaNotificationCenterComponent {
render(): React.ReactNode {
const empty = this.state.notifications.length === 0;
const title = empty ? 'NO NEW NOTIFICATIONS' : 'NOTIFICATIONS';
const title = empty
? nls.localize(
'vscode/notificationsCenter/notificationsEmpty',
'NO NEW NOTIFICATIONS'
)
: nls.localize(
'vscode/notificationsCenter/notifications',
'NOTIFICATIONS'
);
return (
<div
className={`theia-notifications-container theia-notification-center ${
@@ -20,12 +29,18 @@ export class NotificationCenterComponent extends TheiaNotificationCenterComponen
<ul className="theia-notification-actions">
<li
className="collapse"
title="Hide Notification Center"
title={nls.localize(
'vscode/notificationsStatus/hideNotifications',
'Hide Notification Center'
)}
onClick={this.onHide}
/>
<li
className="clear-all"
title="Clear All"
title={nls.localize(
'vscode/notificationsCommands/clearAllNotifications',
'Clear All'
)}
onClick={this.onClearAll}
/>
</ul>

View File

@@ -1,5 +1,6 @@
import * as React from 'react';
import { NotificationComponent as TheiaNotificationComponent } from '@theia/messages/lib/browser/notification-component';
import { nls } from '@theia/core/lib/browser/nls';
export class NotificationComponent extends TheiaNotificationComponent {
render(): React.ReactNode {
@@ -26,7 +27,11 @@ export class NotificationComponent extends TheiaNotificationComponent {
{expandable && (
<li
className={collapsed ? 'expand' : 'collapse'}
title={collapsed ? 'Expand' : 'Collapse'}
title={
collapsed
? nls.localize('theia/messages/expand', 'Expand')
: nls.localize('theia/messages/collapse', 'Collapse')
}
data-message-id={messageId}
onClick={this.onToggleExpansion}
/>
@@ -34,7 +39,7 @@ export class NotificationComponent extends TheiaNotificationComponent {
{!this.isProgress && (
<li
className="clear"
title="Clear"
title={nls.localize('vscode/abstractTree/clear', 'Clear')}
data-message-id={messageId}
onClick={this.onClear}
/>

View File

@@ -15,6 +15,7 @@ import { WorkspaceInputDialog } from './workspace-input-dialog';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { SaveAsSketch } from '../../contributions/save-as-sketch';
import { SingleTextInputDialog } from '@theia/core/lib/browser';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribution {
@@ -57,7 +58,7 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
const parentUri = parent.resource;
const dialog = new WorkspaceInputDialog(
{
title: 'Name for new file',
title: nls.localize('theia/workspace/fileNewName', 'Name for new file'),
parentUri,
validate: (name) => this.validateFileName(name, parent, true),
},
@@ -93,10 +94,17 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
}
const extension = nameWithExt.split('.').pop();
if (!extension) {
return 'Invalid filename.'; // XXX: this should not happen as we forcefully append `.ino` if it's not there.
return nls.localize(
'theia/workspace/invalidFilename',
'Invalid filename.'
); // XXX: this should not happen as we forcefully append `.ino` if it's not there.
}
if (Sketch.Extensions.ALL.indexOf(`.${extension}`) === -1) {
return `.${extension} is not a valid extension.`;
return nls.localize(
'theia/workspace/invalidExtension',
'.{0} is not a valid extension',
extension
);
}
return '';
}
@@ -151,7 +159,7 @@ export class WorkspaceCommandContribution extends TheiaWorkspaceCommandContribut
}
const initialValue = uri.path.base;
const dialog = new SingleTextInputDialog({
title: 'New name for file',
title: nls.localize('theia/workspace/newFileName', 'New name for file'),
initialValue,
initialSelectionRange: {
start: 0,

View File

@@ -3,6 +3,7 @@ import { remote } from 'electron';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceDeleteHandler as TheiaWorkspaceDeleteHandler } from '@theia/workspace/lib/browser/workspace-delete-handler';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class WorkspaceDeleteHandler extends TheiaWorkspaceDeleteHandler {
@@ -21,10 +22,16 @@ export class WorkspaceDeleteHandler extends TheiaWorkspaceDeleteHandler {
.some((uri) => uri === sketch.mainFileUri)
) {
const { response } = await remote.dialog.showMessageBox({
title: 'Delete',
title: nls.localize('vscode/fileActions/delete', 'Delete'),
type: 'question',
buttons: ['Cancel', 'OK'],
message: 'Do you want to delete the current sketch?',
buttons: [
nls.localize('vscode/issueMainService/cancel', 'Cancel'),
nls.localize('vscode/issueMainService/ok', 'OK'),
],
message: nls.localize(
'theia/workspace/deleteCurrentSketch',
'Do you want to delete the current sketch?'
),
});
if (response === 1) {
// OK

View File

@@ -6,6 +6,7 @@ import {
WorkspaceInputDialog as TheiaWorkspaceInputDialog,
WorkspaceInputDialogProps,
} from '@theia/workspace/lib/browser/workspace-input-dialog';
import { nls } from '@theia/core/lib/browser/nls';
export class WorkspaceInputDialog extends TheiaWorkspaceInputDialog {
protected wasTouched = false;
@@ -16,7 +17,9 @@ export class WorkspaceInputDialog extends TheiaWorkspaceInputDialog {
@inject(LabelProvider) protected readonly labelProvider: LabelProvider
) {
super(props, labelProvider);
this.appendCloseButton('Cancel');
this.appendCloseButton(
nls.localize('vscode/issueMainService/cancel', 'Cancel')
);
}
protected appendParentPath(): void {

View File

@@ -17,6 +17,7 @@ import {
import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver';
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
import { BoardsConfig } from '../../boards/boards-config';
import { nls } from '@theia/core/lib/browser/nls';
@injectable()
export class WorkspaceService extends TheiaWorkspaceService {
@@ -89,9 +90,10 @@ export class WorkspaceService extends TheiaWorkspaceService {
.then(() => this.application.shell.update());
this.logger.fatal(`Failed to determine the sketch directory: ${err}`);
this.messageService.error(
'There was an error creating the sketch directory. ' +
'See the log for more details. ' +
'The application will probably not work as expected.'
nls.localize(
'theia/workspace/sketchDirectoryError',
'There was an error creating the sketch directory. See the log for more details. The application will probably not work as expected.'
)
);
return super.getDefaultWorkspaceUri();
}