Skip to content

Commit d1cc554

Browse files
committed
Implement internationalization i18n for panel UI elements and command titles, and add a dictionary entry for "No recently used presets or groups."
1 parent f351295 commit d1cc554

10 files changed

Lines changed: 148 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export const dictionary = {
144144
TYPE_SOMETHING_TO_USE_GROUP: 'Type something to use this group.',
145145
GROUP_HAS_NO_SELECTED_PRESETS:
146146
'The chosen group has no selected presets to run.',
147+
NO_RECENTLY_USED_PRESETS_OR_GROUPS:
148+
'No recently used presets or groups. Select from the list below.',
147149
CHECKPOINT_OPERATION_IN_PROGRESS:
148150
'Another checkpoint operation is currently in progress. Please wait for it to complete.',
149151
URL_OVERRIDE_DIFFERENT_DOMAIN: (preset_name: string) =>

‎packages/vscode/package.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"commands": [
103103
{
104104
"command": "codeWebChat.copyContext",
105-
"title": "Copy Context",
105+
"title": "%codeWebChat.copyContext.title%",
106106
"category": "Code Web Chat",
107107
"icon": "$(copy)"
108108
},
@@ -132,7 +132,7 @@
132132
},
133133
{
134134
"command": "codeWebChat.applyContext",
135-
"title": "Apply Context",
135+
"title": "%codeWebChat.applyContext.title%",
136136
"category": "Code Web Chat",
137137
"icon": "$(checklist)"
138138
},
@@ -144,7 +144,7 @@
144144
},
145145
{
146146
"command": "codeWebChat.findPathsInClipboard",
147-
"title": "Find Paths in Clipboard",
147+
"title": "%codeWebChat.findPathsInClipboard.title%",
148148
"category": "Code Web Chat"
149149
},
150150
{
@@ -217,7 +217,7 @@
217217
},
218218
{
219219
"command": "codeWebChat.applyChatResponse",
220-
"title": "Apply Chat Response",
220+
"title": "%codeWebChat.applyChatResponse.title%",
221221
"category": "Code Web Chat"
222222
},
223223
{
@@ -261,7 +261,7 @@
261261
},
262262
{
263263
"command": "codeWebChat.checkpoints",
264-
"title": "Checkpoints",
264+
"title": "%codeWebChat.checkpoints.title%",
265265
"category": "Code Web Chat",
266266
"icon": "$(history)"
267267
},

‎packages/vscode/package.nls.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"codeWebChat.applyContext.title": "Apply Context",
3+
"codeWebChat.applyChatResponse.title": "Apply Chat Response",
4+
"codeWebChat.copyContext.title": "Copy context",
5+
"codeWebChat.checkpoints.title": "Checkpoints",
6+
"codeWebChat.findPathsInClipboard.title": "Find Paths in Clipboard"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"codeWebChat.applyContext.title": "Wybierz zapisany kontekst",
3+
"codeWebChat.applyChatResponse.title": "Zintegruj wiadomość czatbota",
4+
"codeWebChat.copyContext.title": "Kopiuj kontekst",
5+
"codeWebChat.checkpoints.title": "Punkty kontrolne",
6+
"codeWebChat.findPathsInClipboard.title": "Znajdź ścieżki plików w schowku"
7+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
export const translations = {
2+
en: {
3+
'panel.header.settings': 'Settings',
4+
'panel.header.prompt-type': 'Prompt type',
5+
'settings.sidebar.settings': 'Settings'
6+
},
7+
pl: {
8+
'panel.header.settings': 'Ustawienia',
9+
'panel.header.prompt-type': 'Typ promptu',
10+
'settings.sidebar.settings': 'Ustawienia'
11+
},
12+
'zh-cn': {
13+
'panel.header.settings': '设置',
14+
'panel.header.prompt-type': '提示类型',
15+
'settings.sidebar.settings': '设置'
16+
},
17+
ja: {
18+
'panel.header.settings': '設定',
19+
'panel.header.prompt-type': 'プロンプトタイプ',
20+
'settings.sidebar.settings': '設定'
21+
},
22+
'zh-tw': {
23+
'panel.header.settings': '設定',
24+
'panel.header.prompt-type': '提示類型',
25+
'settings.sidebar.settings': '設定'
26+
},
27+
de: {
28+
'panel.header.settings': 'Einstellungen',
29+
'panel.header.prompt-type': 'Prompt-Typ',
30+
'settings.sidebar.settings': 'Einstellungen'
31+
},
32+
es: {
33+
'panel.header.settings': 'Configuración',
34+
'panel.header.prompt-type': 'Tipo de prompt',
35+
'settings.sidebar.settings': 'Configuración'
36+
},
37+
fr: {
38+
'panel.header.settings': 'Paramètres',
39+
'panel.header.prompt-type': 'Type de prompt',
40+
'settings.sidebar.settings': 'Paramètres'
41+
},
42+
'pt-br': {
43+
'panel.header.settings': 'Configurações',
44+
'panel.header.prompt-type': 'Tipo de prompt',
45+
'settings.sidebar.settings': 'Configurações'
46+
},
47+
ru: {
48+
'panel.header.settings': 'Настройки',
49+
'panel.header.prompt-type': 'Тип промпта',
50+
'settings.sidebar.settings': 'Настройки'
51+
},
52+
ko: {
53+
'panel.header.settings': '설정',
54+
'panel.header.prompt-type': '프롬프트 유형',
55+
'settings.sidebar.settings': '설정'
56+
},
57+
it: {
58+
'panel.header.settings': 'Impostazioni',
59+
'panel.header.prompt-type': 'Tipo di prompt',
60+
'settings.sidebar.settings': 'Impostazioni'
61+
},
62+
tr: {
63+
'panel.header.settings': 'Ayarlar',
64+
'panel.header.prompt-type': 'İstem türü',
65+
'settings.sidebar.settings': 'Ayarlar'
66+
},
67+
cs: {
68+
'panel.header.settings': 'Nastavení',
69+
'panel.header.prompt-type': 'Typ promptu',
70+
'settings.sidebar.settings': 'Nastavení'
71+
},
72+
hu: {
73+
'panel.header.settings': 'Beállítások',
74+
'panel.header.prompt-type': 'Prompt típus',
75+
'settings.sidebar.settings': 'Beállítások'
76+
},
77+
bg: {
78+
'panel.header.settings': 'Настройки',
79+
'panel.header.prompt-type': 'Тип промпт',
80+
'settings.sidebar.settings': 'Настройки'
81+
}
82+
}

‎packages/vscode/src/views/panel/backend/message-handlers/handle-send-prompt.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ async function show_preset_quick_pick(params: {
318318
const recent_names = context.globalState.get<string[]>(recents_key, [])
319319

320320
if (recent_names.length == 0) {
321-
vscode.window.showWarningMessage('No recently used presets or groups.')
321+
vscode.window.showWarningMessage(
322+
dictionary.warning_message.NO_RECENTLY_USED_PRESETS_OR_GROUPS
323+
)
322324
return null
323325
}
324326

@@ -353,7 +355,9 @@ async function show_preset_quick_pick(params: {
353355

354356
quick_pick.items = items
355357
if (items.length == 0) {
356-
vscode.window.showWarningMessage('No recently used presets or groups.')
358+
vscode.window.showWarningMessage(
359+
dictionary.warning_message.NO_RECENTLY_USED_PRESETS_OR_GROUPS
360+
)
357361
return null
358362
}
359363
quick_pick.placeholder = 'Search recently used presets and groups'

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ export class PanelProvider implements vscode.WebviewViewProvider {
899899

900900
return `
901901
<!DOCTYPE html>
902-
<html lang="en">
902+
<html lang="${vscode.env.language}">
903903
<head>
904904
<meta charset="UTF-8">
905905
<meta name="viewport" content="width=device-width, initial-scale=1.0">

‎packages/vscode/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Checkpoint, FrontendMessage } from '@/views/panel/types/messages'
88
import { Responses as UiResponses } from '@ui/components/editor/panel/Responses'
99
import { ResponseHistoryItem } from '@shared/types/response-history-item'
1010
import { Separator } from '@ui/components/editor/panel/Separator'
11+
import { use_translation } from '@/views/panel/frontend/hooks/use-translation'
1112

1213
type Props = {
1314
vscode: any
@@ -26,6 +27,8 @@ type Props = {
2627
}
2728

2829
export const Home: React.FC<Props> = (props) => {
30+
const { t } = use_translation()
31+
2932
const handle_settings_click = () => {
3033
post_message(props.vscode, {
3134
command: 'EXECUTE_COMMAND',
@@ -45,9 +48,9 @@ export const Home: React.FC<Props> = (props) => {
4548
<button
4649
className={styles['header__settings']}
4750
onClick={handle_settings_click}
48-
title="Settings"
51+
title={t('panel.header.settings')}
4952
>
50-
<span>Settings</span>
53+
<span>{t('panel.header.settings')}</span>
5154
<span className={styles['header__settings__icon-wrapper']}>
5255
<span className={cn('codicon', 'codicon-settings-gear')} />
5356
</span>

‎packages/vscode/src/views/panel/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { IconButton as UiIconButton } from '@ui/components/editor/panel/IconButt
88
import styles from './Header.module.scss'
99
import { api_mode_labels, web_mode_labels } from '../../modes'
1010
import { use_keyboard_shortcuts } from './hooks/use-keyboard-shortcuts'
11+
import { use_translation } from '@/views/panel/frontend/hooks/use-translation'
1112

1213
type Props = {
1314
mode: Mode
@@ -21,6 +22,7 @@ type Props = {
2122
}
2223

2324
export const Header: React.FC<Props> = (props) => {
25+
const { t } = use_translation()
2426
const header_ref = useRef<HTMLDivElement>(null)
2527
const is_narrow_viewport = use_is_narrow_viewport(294)
2628
const is_mac = use_is_mac()
@@ -77,7 +79,9 @@ export const Header: React.FC<Props> = (props) => {
7779
selected_value={props.web_prompt_type}
7880
on_change={props.on_web_prompt_type_change}
7981
menu_max_width="calc(100vw - 52px)"
80-
info={is_narrow_viewport ? undefined : 'prompt type'}
82+
info={
83+
is_narrow_viewport ? undefined : t('panel.header.prompt-type')
84+
}
8185
title={
8286
is_mac
8387
? 'Change prompt type (⇧⌥)'
@@ -97,7 +101,9 @@ export const Header: React.FC<Props> = (props) => {
97101
selected_value={props.api_prompt_type}
98102
on_change={props.on_api_prompt_type_change}
99103
menu_max_width="calc(100vw - 60px)"
100-
info={is_narrow_viewport ? undefined : 'prompt type'}
104+
info={
105+
is_narrow_viewport ? undefined : t('panel.header.prompt-type')
106+
}
101107
title={
102108
is_mac
103109
? 'Change prompt type (⇧⌥)'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { translations } from '@/i18n/translations'
2+
3+
type TranslationKey = keyof (typeof translations)['en']
4+
5+
export const use_translation = () => {
6+
let lang = document.documentElement.lang || 'en'
7+
8+
const translations_record = translations as Record<
9+
string,
10+
Record<string, string>
11+
>
12+
13+
// Fallback to generic language code if specific locale not found (e.g. 'pl-PL' -> 'pl')
14+
if (!translations_record[lang]) {
15+
lang = lang.split('-')[0]
16+
}
17+
18+
const current_translations = translations_record[lang] || translations['en']
19+
20+
const t = (key: TranslationKey): string => {
21+
return current_translations[key] || translations['en'][key] || key
22+
}
23+
24+
return { t }
25+
}

0 commit comments

Comments
 (0)