Skip to content

Commit 65b9397

Browse files
committed
Refactor codebase to replace hardcoded strings with dictionary constants for improved localization and maintainability
1 parent e7c5641 commit 65b9397

17 files changed

Lines changed: 253 additions & 106 deletions

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export const dictionary = {
66
},
77

88
information_message: {
9+
ALL_CHECKPOINTS_CLEARED: 'All checkpoints have been cleared.',
10+
ALL_CHECKED_FILES_UNCAHNGED_SINCE_COMMIT: (
11+
folder_name: string,
12+
commit_hash: string
13+
) =>
14+
`All checked files in "${folder_name}" are unchanged since commit ${commit_hash}.`,
915
NO_INTELLIGENT_UPDATE_CONFIGURATIONS_FOUND:
1016
'No "Intelligent Update" configurations found. Please add one in the settings.',
1117
NO_SAFE_FILE_PATHS_REMAINING:
@@ -17,10 +23,19 @@ export const dictionary = {
1723
COPIED_TO_CLIPBOARD: 'Message copied to the clipboard.',
1824
CHECKPOINTS_COPIED_TO_CLIPBOARD:
1925
'Checkpoints copied to clipboard as logs.',
26+
CHECKPOINT_DELETED: (from_now: string) =>
27+
`Checkpoint from ${from_now} deleted.`,
28+
CHECKPOINT_RESTORED: 'Checkpoint restored.',
2029
NO_SAVED_CONTEXTS_IN_WORKSPACE_STATE:
2130
'No saved contexts remaining in the Workspace State.',
2231
NO_SAVED_CONTEXTS_IN_JSON_FILE:
2332
'No saved contexts remaining in the JSON file.',
33+
COMMIT_SEEMS_EMPTY: (commit_hash: string) =>
34+
`Commit ${commit_hash} seems empty.`,
35+
CONFIRM_SAVE_CHANGES_TO_ITEM: (item_type: string) =>
36+
`Save changes to the ${item_type}?`,
37+
COULD_NOT_UNDO_ANOTHER_CHECKPOINT_DELETED:
38+
'Could not undo. Another checkpoint was deleted.',
2439
NO_FILE_PATHS_FOUND_IN_CLIPBOARD: 'No file paths found in the clipboard.',
2540
NO_MATCHING_FILES_FOUND_FOR_CLIPBOARD_PATHS:
2641
'No matching files found in workspace for the paths in clipboard.',
@@ -38,12 +53,62 @@ export const dictionary = {
3853
'No files selected for commit message generation.',
3954
COMMIT_MESSAGE_GENERATION_CANCELLED: 'Commit message generation cancelled.',
4055
NO_CHANGES_TO_COMMIT: 'No changes to commit.',
56+
MODELS_ROUTE_NOT_FOUND: (provider_name: string) =>
57+
`The '/models' route was not found for ${provider_name}. This might mean the provider does not support listing models.`,
58+
MODELS_ROUTE_NOT_FOUND_MANUAL_ENTRY: (provider_name: string) =>
59+
`The '/models' route was not found for ${provider_name}. This might mean the provider does not support listing models. You can enter model name manually.`,
60+
NAMED_TEMPLATE_DELETED: (template_name: string) =>
61+
`Template "${template_name}" has been deleted.`,
62+
NO_CHANGES_FOUND_BETWEEN_BRANCHES: (branch_name: string) =>
63+
`No changes found between current branch and ${branch_name}.`,
64+
NO_CHANGES_FOUND_BETWEEN_BRANCHES_IN_FOLDER: (
65+
branch_name: string,
66+
folder_name: string
67+
) =>
68+
`No changes found between current branch and ${branch_name} in ${folder_name}.`,
69+
NO_CHECKED_FILES_IN_REPO_FOR_COMMIT: (
70+
folder_name: string,
71+
commit_hash: string
72+
) =>
73+
`No checked files in the "${folder_name}" repository for commit ${commit_hash}.`,
4174
NO_DEFAULT_INTELLIGENT_UPDATE_CONFIGURATION:
4275
'No default "Intelligent Update" configuration found. Please set one as default in the settings.',
4376
NO_EDIT_CONTEXT_CONFIGURATIONS_FOUND:
4477
'No "Edit Context" configurations found. Please add one in the settings.',
4578
PRESET_PREVIEW_SENT_TO_BROWSER:
46-
'Preset preview sent to the connected browser.'
79+
'Preset preview sent to the connected browser.',
80+
DELETED_CONTEXT_FROM_ALL_ROOTS: (context_name: string) =>
81+
`Deleted context "${context_name}" from all workspace roots`,
82+
NO_HISTORY_FOR_MODE: 'No history to show for the current mode.',
83+
NO_TEXT_SELECTED_FOR_SELECTION_PLACEHOLDER:
84+
'No text selected for #Selection placeholder.',
85+
PLEASE_CONFIRM: 'Please confirm',
86+
RESTORED_CONTEXT: (context_name: string) =>
87+
`Restored context "${context_name}".`,
88+
NO_GIT_REPOSITORY_FOUND_IN_WORKSPACE:
89+
'No Git repository found in the workspace.',
90+
NO_UNSTAGED_FILES_FOUND: 'No unstaged files found.',
91+
NO_ACTIONABLE_UNSTAGED_FILES_FOUND:
92+
'No actionable unstaged files found (e.g. only deletions).',
93+
SELECTED_FILES: (count: number) =>
94+
`Selected ${count} file${count == 1 ? '' : 's'}.`,
95+
DELETED_CONTEXT_FROM_WORKSPACE_STATE: (context_name: string) =>
96+
`Deleted context "${context_name}" from workspace state`,
97+
CONTEXT_SAVED_TO_JSON: (context_name: string, workspaces: string) =>
98+
`Context "${context_name}" saved to ${workspaces}.`,
99+
CONTEXT_SAVED_TO_WORKSPACE_STATE: (context_name: string) =>
100+
`Context "${context_name}" saved to the workspace state successfully.`,
101+
FILES_REMAIN_CHECKED: (count: number) =>
102+
`${count} file${count == 1 ? '' : 's'} remain${
103+
count == 1 ? 's' : ''
104+
} checked.`,
105+
CRUNCHING_TOKEN_COUNTS: 'Please wait, crunching token counts...',
106+
TEMPLATE_RESTORED: 'Template has been restored.',
107+
UNNAMED_TEMPLATE_DELETED: 'Unnamed template has been deleted.',
108+
UNSAVED_CHANGES_TO_ITEM_WILL_BE_LOST: (item_type: string) =>
109+
`If you don't save, updates to the ${item_type} will be lost.`,
110+
BASE_URL_DOES_NOT_END_WITH_V1:
111+
'The Base URL does not end with "/v1". Many OpenAI-compatible APIs require this. Would you like to add it?'
47112
},
48113

49114
warning_message: {
@@ -89,6 +154,8 @@ export const dictionary = {
89154
`URL override for preset "${preset_name}" was discarded because it uses a different domain.`,
90155
CONTEXT_SIZE_WARNING: (threshold: string, percentage: number) =>
91156
`Context exceeds threshold of ${threshold} tokens by ${percentage}%. Excessive context size affects accuracy and cost-efficiency.`,
157+
COULD_NOT_DELETE_CHECKPOINT_FILES: (message: string) =>
158+
`Could not delete checkpoint files: ${message}`,
92159
FAILED_TO_CREATE_FILE: (file_path: string) =>
93160
`Failed to create file: ${file_path}.`,
94161
FAILED_TO_APPLY_CHANGES_TO_FILE: (file_path: string) =>
@@ -101,10 +168,22 @@ export const dictionary = {
101168
`Could not undo file: ${file_path}. It might have been closed or deleted.`,
102169
NO_VALID_PATHS_IN_CONTEXT: (context_name: string) =>
103170
`No valid paths found in context "${context_name}".`,
171+
CONFIRM_CLEAR_ALL_CHECKPOINTS:
172+
'Are you sure you want to clear all checkpoints? This operation cannot be undone.',
173+
CONFIRM_CLEAR_API_KEY: (provider_name: string) =>
174+
`Are you sure you want to clear the API key for ${provider_name}? This action cannot be undone.`,
104175
CONFIRM_DELETE_CONTEXT: (context_name: string) =>
105176
`Are you sure you want to delete context "${context_name}"?`,
106-
CONFIRM_DELETE_ITEM: (item_type: 'file' | 'folder') =>
177+
CONFIRM_DELETE_ITEM: (item_type: 'file' | 'folder' | 'group' | 'preset') =>
107178
`Are you sure you want to delete this ${item_type}?`,
179+
CONFIRM_DELETE_NAMED_ITEM: (item_type: string, name: string) =>
180+
`Are you sure you want to delete ${item_type} "${name}"?`,
181+
CONTEXT_WITH_IDENTICAL_PATHS_EXISTS: (context_name: string) =>
182+
`A context with identical paths already exists in workspace state: "${context_name}"`,
183+
CONFIRM_OVERWRITE_CONTEXT: (context_name: string) =>
184+
`A context named "${context_name}" already exists. Overwrite?`,
185+
CONFIRM_OVERWRITE_CONTEXT_IN_WORKSPACE_STATE: (context_name: string) =>
186+
`A context named "${context_name}" already exists in Workspace State. Overwrite?`,
108187
SAVED_CONTEXT_NOT_FOUND: (name: string, source: string) =>
109188
`Saved context "${name}" from ${source} not found.`,
110189
CONFIRM_DELETE_CONFIGURATION: (model: string, provider: string) =>
@@ -164,6 +243,8 @@ export const dictionary = {
164243
FAILED_TO_COMMIT_CHANGES: 'Failed to commit changes.',
165244
ERROR_COMMITTING_CHANGES:
166245
'Error committing changes. See console for details.',
246+
FAILED_TO_SELECT_UNSTAGED_FILES: (message: string) =>
247+
`Failed to select unstaged files: ${message}.`,
167248
FAILED_TO_DELETE: (message: string) => `Failed to delete: ${message}.`,
168249
ERROR_GENERATING_COMMIT_MESSAGE:
169250
'Error generating commit message. See console for details.',
@@ -205,6 +286,8 @@ export const dictionary = {
205286
API_KEY_MISSING_FOR_PROVIDER:
206287
'API key is missing for the selected provider. Please add it in the Settings tab.',
207288
FAILED_TO_GENERATE_COMMIT_MESSAGE: 'Failed to generate commit message.',
289+
CHECKPOINTS_ONLY_IN_WORKSPACE:
290+
'Checkpoints can only be used in a workspace.',
208291
GIT_EXTENSION_NOT_FOUND: 'Git extension not found.',
209292
NO_GIT_REPOSITORY_FOUND: 'No Git repository found.',
210293
REPOSITORY_NOT_FOUND: 'Repository not found.',
@@ -229,10 +312,15 @@ export const dictionary = {
229312
`Failed to duplicate preset: ${error}.`,
230313
WORKSPACE_NOT_FOUND_FOR_FILE: (file_path: string) =>
231314
`Workspace not found for file: ${file_path}.`,
315+
WORKSPACE_FOLDER_NOT_FOUND: (folder_name: string) =>
316+
`Workspace folder "${folder_name}" not found.`,
232317
COULD_NOT_OPEN_FILE: (file_path: string) =>
233318
`Could not open file: ${file_path}.`,
234319
API_PROVIDER_FOR_DEFAULT_CONFIG_NOT_FOUND:
235320
'API provider for the default API tool configuration was not found.',
321+
COULD_NOT_FIND_TEMP_CHECKPOINT_TO_REVERT:
322+
'Could not find temporary checkpoint to revert.',
323+
COULD_NOT_GET_GIT_API: 'Could not get Git API.',
236324
INTELLIGENT_UPDATE_CONTEXT_NOT_FOUND:
237325
'Could not find the context for intelligent update. Please apply the changes again.',
238326
ORIGINAL_STATE_FOR_FILE_NOT_FOUND: (file_name: string) =>
@@ -243,6 +331,15 @@ export const dictionary = {
243331
`Intelligent update failed for ${file_name}: ${message}.`,
244332
FAILED_TO_FETCH_OPEN_ROUTER_MODELS:
245333
'Failed to fetch Open Router models. Please check your connection.',
334+
FAILED_TO_GET_CHANGES_FROM_BRANCH: (branch_name: string) =>
335+
`Failed to get changes from branch ${branch_name}. Make sure the branch exists.`,
336+
FAILED_TO_GET_CHANGES_FROM_BRANCH_IN_FOLDER: (
337+
branch_name: string,
338+
folder_name: string
339+
) =>
340+
`Failed to get changes from branch ${branch_name} in ${folder_name}. Make sure the branch exists.`,
341+
FAILED_TO_GET_DIFF_FOR_COMMIT: (commit_hash: string) =>
342+
`Failed to get diff for commit ${commit_hash}.`,
246343
COULD_NOT_UPDATE_ITEM_NOT_FOUND: (item_type: string, name: string) =>
247344
`Could not update ${item_type}: Original ${item_type} "${name}" not found.`,
248345
ERROR_HANDLING_MESSAGE: (message: string) =>

‎packages/vscode/src/commands/apply-context-command/sources/json-file-source.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ export async function handle_json_file_source(
381381
}
382382
} catch (error: any) {
383383
vscode.window.showErrorMessage(
384-
`Error deleting context from ${path.basename(root)}: ${
385-
error.message
386-
}`
384+
dictionary.error_message.ERROR_DELETING_CONTEXT_FROM_FILE(error.message)
387385
)
388386
}
389387
}
@@ -395,7 +393,9 @@ export async function handle_json_file_source(
395393

396394
is_showing_dialog = true
397395
const choice = await vscode.window.showInformationMessage(
398-
`Deleted context "${deleted_context_name}" from all workspace roots`,
396+
dictionary.information_message.DELETED_CONTEXT_FROM_ALL_ROOTS(
397+
deleted_context_name
398+
),
399399
'Undo'
400400
)
401401
is_showing_dialog = false
@@ -411,7 +411,9 @@ export async function handle_json_file_source(
411411
await save_contexts_to_file(original_contexts, file_path)
412412
} catch (error: any) {
413413
vscode.window.showErrorMessage(
414-
`Failed to undo context deletion in ${file_path}: ${error.message}`
414+
dictionary.error_message.FAILED_TO_UNDO_CHANGES(
415+
`Failed to restore context in ${file_path}: ${error.message}`
416+
)
415417
)
416418
success = false
417419
}
@@ -422,7 +424,9 @@ export async function handle_json_file_source(
422424
file_contexts = reloaded.merged
423425
context_to_roots = reloaded.context_to_roots
424426
vscode.window.showInformationMessage(
425-
`Restored context "${deleted_context_name}".`
427+
dictionary.information_message.RESTORED_CONTEXT(
428+
deleted_context_name
429+
)
426430
)
427431
quick_pick.items = create_quick_pick_items(file_contexts)
428432
}

‎packages/vscode/src/commands/apply-context-command/sources/unstaged-files-source.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import * as fs from 'fs'
44
import { WorkspaceProvider } from '../../../context/providers/workspace-provider'
5+
import { dictionary } from '@shared/constants/dictionary'
56
import { Logger } from '@shared/utils/logger'
67
import { display_token_count } from '../../../utils/display-token-count'
78

@@ -11,18 +12,22 @@ export async function handle_unstaged_files_source(
1112
try {
1213
const git_extension = vscode.extensions.getExtension('vscode.git')?.exports
1314
if (!git_extension) {
14-
vscode.window.showErrorMessage('Git extension is not available.')
15+
vscode.window.showErrorMessage(
16+
dictionary.error_message.GIT_EXTENSION_NOT_FOUND
17+
)
1518
return
1619
}
1720
const git_api = git_extension.getAPI(1)
1821
if (!git_api) {
19-
vscode.window.showErrorMessage('Could not get Git API.')
22+
vscode.window.showErrorMessage(
23+
dictionary.error_message.COULD_NOT_GET_GIT_API
24+
)
2025
return
2126
}
2227

2328
if (git_api.repositories.length === 0) {
2429
vscode.window.showInformationMessage(
25-
'No Git repository found in the workspace.'
30+
dictionary.information_message.NO_GIT_REPOSITORY_FOUND_IN_WORKSPACE
2631
)
2732
return
2833
}
@@ -35,7 +40,9 @@ export async function handle_unstaged_files_source(
3540
}
3641

3742
if (unstaged_file_paths.length === 0) {
38-
vscode.window.showInformationMessage('No unstaged files found.')
43+
vscode.window.showInformationMessage(
44+
dictionary.information_message.NO_UNSTAGED_FILES_FOUND
45+
)
3946
return
4047
}
4148

@@ -49,7 +56,7 @@ export async function handle_unstaged_files_source(
4956

5057
if (existing_unstaged_files.length == 0) {
5158
vscode.window.showInformationMessage(
52-
'No actionable unstaged files found (e.g. only deletions).'
59+
dictionary.information_message.NO_ACTIONABLE_UNSTAGED_FILES_FOUND
5360
)
5461
return
5562
}
@@ -97,15 +104,13 @@ export async function handle_unstaged_files_source(
97104

98105
await workspace_provider.set_checked_files(selected_paths)
99106
vscode.window.showInformationMessage(
100-
`Selected ${selected_paths.length} file${
101-
selected_paths.length == 1 ? '' : 's'
102-
}.`
107+
dictionary.information_message.SELECTED_FILES(selected_paths.length)
103108
)
104109
} catch (error) {
105110
vscode.window.showErrorMessage(
106-
`Failed to select unstaged files: ${
111+
dictionary.error_message.FAILED_TO_SELECT_UNSTAGED_FILES(
107112
error instanceof Error ? error.message : String(error)
108-
}`
113+
)
109114
)
110115
Logger.error({
111116
function_name: 'apply_context_command:unstaged',

‎packages/vscode/src/commands/apply-context-command/sources/workspace-state-source.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ export async function handle_workspace_state_source(
207207

208208
is_showing_dialog = true
209209
const choice = await vscode.window.showInformationMessage(
210-
`Deleted context "${deleted_context_name}" from workspace state`,
210+
dictionary.information_message.DELETED_CONTEXT_FROM_WORKSPACE_STATE(
211+
deleted_context_name
212+
),
211213
'Undo'
212214
)
213215
is_showing_dialog = false
@@ -218,8 +220,10 @@ export async function handle_workspace_state_source(
218220
SAVED_CONTEXTS_STATE_KEY,
219221
internal_contexts
220222
)
221-
vscode.window.showInformationMessage(
222-
`Restored context "${deleted_context_name}".`
223+
vscode.window.showInformationMessage( // NOSONAR
224+
dictionary.information_message.RESTORED_CONTEXT(
225+
deleted_context_name
226+
)
223227
)
224228
quick_pick.items = create_quick_pick_items(internal_contexts)
225229
}

0 commit comments

Comments
 (0)