Skip to content

Commit b05b8ff

Browse files
authored
Enhance localization of the ai-chat package (eclipse-theia#16409)
1 parent 0b1aab1 commit b05b8ff

14 files changed

+78
-38
lines changed

packages/ai-chat/src/browser/change-set-file-element.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// *****************************************************************************
1616

1717
import { ConfigurableInMemoryResources, ConfigurableMutableReferenceResource } from '@theia/ai-core';
18-
import { CancellationToken, DisposableCollection, Emitter, URI } from '@theia/core';
18+
import { CancellationToken, DisposableCollection, Emitter, nls, URI } from '@theia/core';
1919
import { ConfirmDialog } from '@theia/core/lib/browser';
2020
import { Replacement } from '@theia/core/lib/common/content-replacer';
2121
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
@@ -448,12 +448,18 @@ export class ChangeSetFileElement implements ChangeSetElement {
448448
}
449449
}
450450

451-
async confirm(verb: string): Promise<boolean> {
451+
async confirm(verb: 'Apply' | 'Revert'): Promise<boolean> {
452452
if (this._state !== 'stale') { return true; }
453453
await this.openChange();
454454
const answer = await new ConfirmDialog({
455-
title: `${verb} suggestion.`,
456-
msg: `The file ${this.uri.path.toString()} has changed since this suggestion was created. Are you certain you wish to ${verb.toLowerCase()} the change?`
455+
title: verb === 'Apply'
456+
? nls.localize('theia/ai/chat/applySuggestion', 'Apply suggestion')
457+
: nls.localize('theia/ai/chat/revertSuggestion', 'Revert suggestion'),
458+
msg: verb === 'Apply'
459+
? nls.localize('theia/ai/chat/confirmApplySuggestion',
460+
'The file {0} has changed since this suggestion was created. Are you certain you wish to apply the change?', this.uri.path.toString())
461+
: nls.localize('theia/ai/chat/confirmRevertSuggestion',
462+
'The file {0} has changed since this suggestion was created. Are you certain you wish to revert the change?', this.uri.path.toString())
457463
}).open(true);
458464
return !!answer;
459465
}

packages/ai-chat/src/browser/change-set-file-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
1515
// *****************************************************************************
1616

17-
import { ILogger, URI } from '@theia/core';
17+
import { ILogger, nls, URI } from '@theia/core';
1818
import { ApplicationShell, DiffUris, LabelProvider, NavigatableWidget, OpenerService, open } from '@theia/core/lib/browser';
1919
import { inject, injectable } from '@theia/core/shared/inversify';
2020
import { EditorManager } from '@theia/editor/lib/browser';
@@ -79,7 +79,7 @@ export class ChangeSetFileService {
7979
if (wsUri) {
8080
const wsRelative = wsUri.relative(uri);
8181
if (wsRelative?.hasDir) {
82-
return `${wsRelative.dir.toString()}`;
82+
return wsRelative.dir.toString();
8383
}
8484
return '';
8585
}
@@ -104,7 +104,7 @@ export class ChangeSetFileService {
104104

105105
protected getDiffUri(originalUri: URI, suggestedUri: URI): URI {
106106
return DiffUris.encode(originalUri, suggestedUri,
107-
`AI Changes: ${this.labelProvider.getName(originalUri)}`,
107+
nls.localize('theia/ai/chat/changeSetFileDiffUriLabel', 'AI Changes: {0}', this.labelProvider.getName(originalUri)),
108108
);
109109
}
110110

packages/ai-chat/src/browser/file-chat-variable-contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { AIVariableContext, AIVariableResolutionRequest, PromptText } from '@theia/ai-core';
1818
import { AIVariableCompletionContext, AIVariableDropResult, FrontendVariableContribution, FrontendVariableService } from '@theia/ai-core/lib/browser';
1919
import { FILE_VARIABLE } from '@theia/ai-core/lib/browser/file-variable-contribution';
20-
import { CancellationToken, ILogger, QuickInputService, URI } from '@theia/core';
20+
import { CancellationToken, ILogger, nls, QuickInputService, URI } from '@theia/core';
2121
import { inject, injectable } from '@theia/core/shared/inversify';
2222
import * as monaco from '@theia/monaco-editor-core';
2323
import { FileQuickPickItem, QuickFileSelectService } from '@theia/file-search/lib/browser/quick-file-select-service';
@@ -76,7 +76,7 @@ export class FileChatVariableContribution implements FrontendVariableContributio
7676

7777
protected async imageArgumentPicker(): Promise<string | undefined> {
7878
const quickPick = this.quickInputService.createQuickPick();
79-
quickPick.title = 'Select an image file';
79+
quickPick.title = nls.localize('theia/ai/chat/selectImageFile', 'Select an image file');
8080

8181
// Get all files and filter only image files
8282
const allPicks = await this.quickFileSelectService.getPicks();

packages/ai-chat/src/browser/image-context-variable-contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ export class ImageContextVariableContribution implements AIVariableContribution,
148148

149149
getDetails(element: ImageContextVariableRequest): string | undefined {
150150
const path = ImageContextVariable.parseArg(element.arg).wsRelativePath;
151-
return path ? this.labelProvider.getDetails(new URI(path)) : '[pasted]';
151+
return path ? this.labelProvider.getDetails(new URI(path)) : undefined;
152152
}
153153
}

packages/ai-chat/src/browser/task-context-service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// *****************************************************************************
1616

1717
import { inject, injectable } from '@theia/core/shared/inversify';
18-
import { MaybePromise, ProgressService, URI, generateUuid, Event, EOL } from '@theia/core';
18+
import { MaybePromise, ProgressService, URI, generateUuid, Event, EOL, nls } from '@theia/core';
1919
import { ChatAgent, ChatAgentLocation, ChatService, ChatSession, MutableChatModel, MutableChatRequestModel, ParsedChatRequestTextPart } from '../common';
2020
import { PreferenceService } from '@theia/core/lib/common';
2121
import { ChatSessionSummaryAgent } from '../common/chat-session-summary-agent';
@@ -90,7 +90,10 @@ export class TaskContextService {
9090
if (existing && !override) { return existing.id; }
9191
const summaryId = generateUuid();
9292
const summaryDeferred = new Deferred<Summary>();
93-
const progress = await this.progressService.showProgress({ text: `Summarize: ${session.title || session.id}`, options: { location: 'ai-chat' } });
93+
const progress = await this.progressService.showProgress({
94+
text: nls.localize('theia/ai/chat/taskContextService/summarizeProgressMessage', 'Summarize: {0}', session.title || session.id),
95+
options: { location: 'ai-chat' }
96+
});
9497
this.pendingSummaries.set(session.id, summaryDeferred.promise);
9598
try {
9699
const prompt = await this.getSystemPrompt(session, promptId);
@@ -127,7 +130,10 @@ export class TaskContextService {
127130
return this.summarize(session, promptId, agent, override);
128131
}
129132

130-
const progress = await this.progressService.showProgress({ text: `Updating: ${session.title || session.id}`, options: { location: 'ai-chat' } });
133+
const progress = await this.progressService.showProgress({
134+
text: nls.localize('theia/ai/chat/taskContextService/updatingProgressMessage', 'Updating: {0}', session.title || session.id),
135+
options: { location: 'ai-chat' }
136+
});
131137
try {
132138
const prompt = await this.getSystemPrompt(session, promptId);
133139
if (!prompt) {

packages/ai-chat/src/browser/task-context-variable.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@
1515
// *****************************************************************************
1616

1717
import { AIVariable } from '@theia/ai-core';
18+
import { nls } from '@theia/core';
1819
import { codiconArray } from '@theia/core/lib/browser';
1920

2021
export const TASK_CONTEXT_VARIABLE: AIVariable = {
2122
id: 'taskContext',
22-
description: 'Provides context information for a task, e.g. the plan for completing a task or a summary of a previous sessions',
23+
description: nls.localize('theia/chat/taskContextVariable/description',
24+
'Provides context information for a task, e.g. the plan for completing a task or a summary of a previous sessions'),
2325
name: 'taskContext',
24-
label: 'Task Context',
26+
label: nls.localize('theia/chat/taskContextVariable/label', 'Task Context'),
2527
iconClasses: codiconArray('clippy'),
2628
isContextVariable: true,
27-
args: [{ name: 'context-id', description: 'The ID of the task context to retrieve, or a chat session to summarize.' }]
29+
args: [{
30+
name: 'context-id',
31+
description: nls.localize('theia/chat/taskContextVariable/args/contextId/description', 'The ID of the task context to retrieve, or a chat session to summarize.')
32+
}]
2833
};

packages/ai-chat/src/common/change-set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
1515
// *****************************************************************************
1616

17-
import { ArrayUtils, Disposable, Emitter, Event, URI } from '@theia/core';
17+
import { ArrayUtils, Disposable, Emitter, Event, nls, URI } from '@theia/core';
1818

1919
export interface ChangeSetElement {
2020
readonly uri: URI;
@@ -95,7 +95,7 @@ export class ChangeSetImpl implements ChangeSet {
9595

9696
protected hasBeenSet = false;
9797
protected _elements = new Map<string, ChangeSetElement | undefined>();
98-
protected _title = 'Suggested Changes';
98+
protected _title = nls.localize('theia/ai/chat/changeSetDefaultTitle', 'Suggested Changes');
9999
get title(): string {
100100
return this._title;
101101
}

packages/ai-chat/src/common/chat-agents-variable-contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//
1414
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
1515
// *****************************************************************************
16-
import { MaybePromise } from '@theia/core';
16+
import { MaybePromise, nls } from '@theia/core';
1717
import { inject, injectable } from '@theia/core/shared/inversify';
1818
import {
1919
AIVariable,
@@ -29,7 +29,7 @@ import { ChatAgentService } from './chat-agent-service';
2929
export const CHAT_AGENTS_VARIABLE: AIVariable = {
3030
id: 'chatAgents',
3131
name: 'chatAgents',
32-
description: 'Returns the list of chat agents available in the system'
32+
description: nls.localize('theia/ai/chat/chatAgentsVariable/description', 'Returns the list of chat agents available in the system')
3333
};
3434

3535
export interface ChatAgentDescriptor {

packages/ai-chat/src/common/chat-agents.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
LanguageModelRegistry,
5050
LanguageModelStreamResponsePart
5151
} from '@theia/ai-core/lib/common';
52-
import { ContributionProvider, ILogger, isArray } from '@theia/core';
52+
import { ContributionProvider, ILogger, isArray, nls } from '@theia/core';
5353
import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify';
5454
import { ChatAgentService } from './chat-agent-service';
5555
import {
@@ -155,7 +155,7 @@ export abstract class AbstractChatAgent implements ChatAgent {
155155
readonly abstract languageModelRequirements: LanguageModelRequirement[];
156156
iconClass: string = 'codicon codicon-copilot';
157157
locations: ChatAgentLocation[] = ChatAgentLocation.ALL;
158-
tags: string[] = ['Chat'];
158+
tags: string[] = [nls.localizeByDefault('Chat')];
159159
description: string = '';
160160
variables: string[] = [];
161161
prompts: PromptVariantSet[] = [];
@@ -180,7 +180,7 @@ export abstract class AbstractChatAgent implements ChatAgent {
180180
try {
181181
const languageModel = await this.getLanguageModel(this.defaultLanguageModelPurpose);
182182
if (!languageModel) {
183-
throw new Error('Couldn\'t find a matching language model. Please check your setup!');
183+
throw new Error(nls.localize('theia/ai/chat/couldNotFindMatchingLM', 'Couldn\'t find a matching language model. Please check your setup!'));
184184
}
185185
const systemMessageDescription = await this.getSystemMessageDescription({ model: request.session, request } satisfies ChatSessionContext);
186186
const messages = await this.getMessages(request.session);
@@ -237,7 +237,7 @@ export abstract class AbstractChatAgent implements ChatAgent {
237237
protected async selectLanguageModel(selector: LanguageModelRequirement): Promise<LanguageModel> {
238238
const languageModel = await this.languageModelRegistry.selectLanguageModel({ agent: this.id, ...selector });
239239
if (!languageModel) {
240-
throw new Error(`Couldn\'t find a ready language model for agent ${this.id}. Please check your setup!`);
240+
throw new Error(nls.localize('theia/ai/chat/couldNotFindReadyLMforAgent', 'Couldn\'t find a ready language model for agent {0}. Please check your setup!', this.id));
241241
}
242242
return languageModel;
243243
}

packages/ai-chat/src/common/chat-session-naming-service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from '@theia/ai-core';
2727
import { inject, injectable } from '@theia/core/shared/inversify';
2828
import { ChatSession } from './chat-service';
29-
import { generateUuid } from '@theia/core';
29+
import { generateUuid, nls } from '@theia/core';
3030

3131
import { CHAT_SESSION_NAMING_PROMPT } from './chat-session-naming-prompt-template';
3232

@@ -47,16 +47,24 @@ export class ChatSessionNamingAgent implements Agent {
4747
static ID = 'Chat Session Naming';
4848
id = ChatSessionNamingAgent.ID;
4949
name = ChatSessionNamingAgent.ID;
50-
description = 'Agent for generating chat session names';
50+
description = nls.localize('theia/ai/chat/chatSessionNamingAgent/description', 'Agent for generating chat session names');
5151
variables = [];
5252
prompts = [CHAT_SESSION_NAMING_PROMPT];
5353
languageModelRequirements: LanguageModelRequirement[] = [{
5454
purpose: 'chat-session-naming',
5555
identifier: 'default/summarize',
5656
}];
5757
agentSpecificVariables = [
58-
{ name: 'conversation', usedInPrompt: true, description: 'The content of the chat conversation.' },
59-
{ name: 'listOfSessionNames', usedInPrompt: true, description: 'The list of existing session names.' }
58+
{
59+
name: 'conversation',
60+
usedInPrompt: true,
61+
description: nls.localize('theia/ai/chat/chatSessionNamingAgent/vars/conversation/description', 'The content of the chat conversation.')
62+
},
63+
{
64+
name: 'listOfSessionNames',
65+
usedInPrompt: true,
66+
description: nls.localize('theia/ai/chat/chatSessionNamingAgent/vars/listOfSessionNames/description', 'The list of existing session names.')
67+
}
6068
];
6169
functions = [];
6270

0 commit comments

Comments
 (0)