Skip to content

Commit 6b08176

Browse files
committed
chore: use lexicons
1 parent fdbb562 commit 6b08176

File tree

21 files changed

+227
-241
lines changed

21 files changed

+227
-241
lines changed

_build/js/src/executor.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const services: ServiceHandlers = {
177177
const content = data?.choices?.[0]?.message?.content;
178178

179179
if (!content) {
180-
throw new Error(lng('modai.cmp.failed_request'));
180+
throw new Error(lng('modai.error.failed_request'));
181181
}
182182

183183
const id = data.id;
@@ -194,7 +194,7 @@ const services: ServiceHandlers = {
194194
url = data?.data?.[0]?.b64_json;
195195

196196
if (!url) {
197-
throw new Error(lng('modai.cmp.failed_request'));
197+
throw new Error(lng('modai.error.failed_request'));
198198
}
199199

200200
url = `data:image/png;base64,${url}`;
@@ -211,7 +211,7 @@ const services: ServiceHandlers = {
211211
const content = data?.content?.[0]?.text;
212212

213213
if (!content) {
214-
throw new Error(lng('modai.cmp.failed_request'));
214+
throw new Error(lng('modai.error.failed_request'));
215215
}
216216

217217
const id = data.id;
@@ -227,7 +227,7 @@ const services: ServiceHandlers = {
227227
const content = data?.candidates?.[0]?.content?.parts?.[0]?.text;
228228

229229
if (!content) {
230-
throw new Error(lng('modai.cmp.failed_request'));
230+
throw new Error(lng('modai.error.failed_request'));
231231
}
232232

233233
return {
@@ -239,7 +239,7 @@ const services: ServiceHandlers = {
239239
const base64 = data?.predictions?.[0]?.bytesBase64Encoded;
240240

241241
if (!base64) {
242-
throw new Error(lng('modai.cmp.failed_request'));
242+
throw new Error(lng('modai.error.failed_request'));
243243
}
244244

245245
return {
@@ -456,7 +456,7 @@ const serviceExecutor = async <D extends ServiceResponse>(
456456

457457
const callStreamService = async (details: ForExecutor) => {
458458
if (executorDetails.parser !== 'content') {
459-
throw new Error(lng('modai.cmp.service_unsupported'));
459+
throw new Error(lng('modai.error.service_unsupported'));
460460
}
461461

462462
const res = await fetch(details.url, {
@@ -477,15 +477,15 @@ const serviceExecutor = async <D extends ServiceResponse>(
477477
};
478478

479479
if (!executorDetails.service || !executorDetails.parser) {
480-
throw new Error(lng('modai.cmp.service_required'));
480+
throw new Error(lng('modai.error.service_required'));
481481
}
482482

483483
if (
484484
!services[executorDetails.stream ? 'stream' : ('buffered' as BufferMode)]?.[
485485
executorDetails.service as ServiceType
486486
]?.[executorDetails.parser as keyof ServiceHandlers[BufferMode][ServiceType]]
487487
) {
488-
throw new Error(lng('modai.cmp.service_unsupported'));
488+
throw new Error(lng('modai.error.service_unsupported'));
489489
}
490490

491491
if (executorDetails.stream) {
@@ -558,7 +558,7 @@ const aiFetch = async <D extends ServiceResponse>(
558558

559559
if (!service || !parser) {
560560
controller.abort();
561-
throw new Error(lng('modai.cmp.service_required'));
561+
throw new Error(lng('modai.error.service_required'));
562562
}
563563

564564
if (
@@ -567,7 +567,7 @@ const aiFetch = async <D extends ServiceResponse>(
567567
]
568568
) {
569569
controller.abort();
570-
throw new Error(lng('modai.cmp.service_unsupported'));
570+
throw new Error(lng('modai.error.service_unsupported'));
571571
}
572572

573573
if (!stream) {
@@ -578,7 +578,7 @@ const aiFetch = async <D extends ServiceResponse>(
578578
}
579579

580580
if (parser !== 'content') {
581-
throw new Error(lng('modai.cmp.service_unsupported'));
581+
throw new Error(lng('modai.error.service_unsupported'));
582582
}
583583

584584
return (await handleStream(

_build/js/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { chatHistory } from './chatHistory';
22
import { executor } from './executor';
33
import { globalState } from './globalState';
44
import { history } from './history';
5+
import { lng } from './lng';
56
import { initOnResource } from './resource';
67
import { ui } from './ui';
78

@@ -20,6 +21,7 @@ export const init = (config: Config) => {
2021
history,
2122
executor,
2223
ui,
24+
lng,
2325
initOnResource,
2426
};
2527
};

_build/js/src/ui/cofirmDialog/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { lng } from '../../lng';
12
import { button } from '../dom/button';
23
import { createModAIShadow } from '../dom/modAIShadow';
34
import { createElement } from '../utils';
@@ -33,7 +34,7 @@ export const confirmDialog = (config: ConfirmDialogOptions) => {
3334
});
3435

3536
const cancelBtn = button(
36-
config.cancelText ?? 'Cancel',
37+
config.cancelText ?? lng('modai.ui.cancel'),
3738
() => {
3839
closeDialog();
3940
},

_build/js/src/ui/generateButton/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const createWandEl = <R extends HTMLElement>(onClick: () => void | Promise<void>
4141
'modai--root generate',
4242
button(icon(14, sparkle), onClick, 'btn', {
4343
type: 'button',
44-
title: 'Generate using AI',
44+
title: lng('modai.ui.generate_using_ai'),
4545
}),
4646
);
4747

@@ -59,7 +59,7 @@ const createHistoryNav = (cache: ReturnType<typeof history.init<DataContext>>) =
5959
'history--prev',
6060
{
6161
type: 'button',
62-
title: 'Previous Version',
62+
title: lng('modai.ui.previous_version'),
6363
role: 'navigation',
6464
},
6565
);
@@ -72,7 +72,7 @@ const createHistoryNav = (cache: ReturnType<typeof history.init<DataContext>>) =
7272
'history--next',
7373
{
7474
type: 'button',
75-
title: 'Next Version',
75+
title: lng('modai.ui.next_version'),
7676
role: 'navigation',
7777
},
7878
);
@@ -154,7 +154,7 @@ const createForcedTextPrompt = ({
154154
done();
155155
confirmDialog({
156156
title: 'Failed',
157-
content: lng('modai.cmp.failed_try_again', {
157+
content: lng('modai.error.failed_try_again', {
158158
msg: err instanceof Error ? err.message : '',
159159
}),
160160
confirmText: 'Close',
@@ -260,11 +260,11 @@ const createVisionPrompt = (config: VisionConfig & Target) => {
260260
} catch (err) {
261261
done();
262262
confirmDialog({
263-
title: 'Failed',
264-
content: lng('modai.cmp.failed_try_again', {
263+
title: lng('modai.error.failed'),
264+
content: lng('modai.error.failed_try_again', {
265265
msg: err instanceof Error ? err.message : '',
266266
}),
267-
confirmText: 'Close',
267+
confirmText: lng('modai.ui.close'),
268268
showCancel: false,
269269
onConfirm: () => {},
270270
});

_build/js/src/ui/localChat/actionButton.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { globalState } from '../../globalState';
2+
import { lng } from '../../lng';
23
import { button } from '../dom/button';
34
import { check } from '../icons';
45
import { createElement } from '../utils';
@@ -53,7 +54,7 @@ export const createActionButton = (config: ActionButtonConfig) => {
5354

5455
if (!config.disableCompletedState) {
5556
icon.innerHTML = check;
56-
label.innerHTML = config.completedText || 'Completed!';
57+
label.innerHTML = config.completedText || lng('modai.ui.completed');
5758

5859
await new Promise((resolve) => setTimeout(resolve, 2000));
5960
}

_build/js/src/ui/localChat/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { closeModal, sendMessage } from './modalActions';
22
import { buildModal } from './modalBuilder';
33
import { globalState } from '../../globalState';
4+
import { lng } from '../../lng';
45

56
import type { LocalChatConfig } from './types';
67

@@ -12,7 +13,7 @@ export const createModal = (config: LocalChatConfig) => {
1213
}
1314

1415
if (!config.key) {
15-
alert('key is required config property');
16+
alert(lng('modai.error.key_required'));
1617
return;
1718
}
1819

_build/js/src/ui/localChat/messageHandlers.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ export const addUserMessage = (msg: Message) => {
5151
disabled: globalState.modal.isLoading,
5252
disableCompletedState: true,
5353
icon: icon(14, edit),
54-
label: 'Edit',
54+
label: lng('modai.ui.edit'),
5555
onClick: (msg) => {
5656
globalState.alertOpen = true;
5757
confirmDialog({
58-
title: 'Confirm Edit',
59-
content:
60-
'Editing this message will delete all responses that came after it. Do you want to proceed?',
61-
confirmText: 'Edit Message',
58+
title: lng('modai.ui.confirm_edit'),
59+
content: lng('modai.ui.confirm_edit_content'),
60+
confirmText: lng('modai.ui.edit_message'),
6261
onCancel: () => {
6362
globalState.alertOpen = false;
6463
},
@@ -138,8 +137,8 @@ export const addAssistantMessage = (msg: Message, config: LocalChatConfig) => {
138137
message: msg,
139138
disabled: globalState.modal.isLoading,
140139
icon: icon(14, copy),
141-
label: 'Copy',
142-
completedText: 'Copied!',
140+
label: lng('modai.ui.copy'),
141+
completedText: lng('modai.ui.copied'),
143142
onClick:
144143
typeof config.textActions?.copy === 'function'
145144
? config.textActions.copy
@@ -154,8 +153,8 @@ export const addAssistantMessage = (msg: Message, config: LocalChatConfig) => {
154153
message: msg,
155154
disabled: globalState.modal.isLoading,
156155
icon: icon(14, plus),
157-
label: 'Insert',
158-
completedText: 'Inserted!',
156+
label: lng('modai.ui.insert'),
157+
completedText: lng('modai.ui.inserted'),
159158
onClick: config.textActions.insert,
160159
}),
161160
);
@@ -169,9 +168,9 @@ export const addAssistantMessage = (msg: Message, config: LocalChatConfig) => {
169168
message: msg,
170169
disabled: globalState.modal.isLoading,
171170
icon: icon(14, copy),
172-
label: 'Copy',
173-
loadingText: 'Downloading...',
174-
completedText: 'Copied!',
171+
label: lng('modai.ui.copy'),
172+
loadingText: lng('modai.ui.downloading'),
173+
completedText: lng('modai.ui.copied'),
175174
onClick: async (msg, modal) => {
176175
const handler =
177176
typeof config.textActions?.copy === 'function'
@@ -208,9 +207,9 @@ export const addAssistantMessage = (msg: Message, config: LocalChatConfig) => {
208207
message: msg,
209208
disabled: globalState.modal.isLoading,
210209
icon: icon(14, plus),
211-
label: 'Insert',
212-
completedText: 'Inserted!',
213-
loadingText: 'Downloading...',
210+
label: lng('modai.ui.insert'),
211+
completedText: lng('modai.ui.inserted'),
212+
loadingText: lng('modai.ui.downloading'),
214213
onClick: async (msg, modal) => {
215214
if (msg.ctx.downloaded === true) {
216215
insertCb(msg, modal);
@@ -278,7 +277,7 @@ export const copyToClipboard = async (message: Message) => {
278277
try {
279278
await navigator.clipboard.writeText(textContent);
280279
} catch {
281-
addErrorMessage(lng('modai.cmp.failed_copy'));
280+
addErrorMessage(lng('modai.error.failed_copy'));
282281
}
283282
} else {
284283
try {
@@ -290,7 +289,7 @@ export const copyToClipboard = async (message: Message) => {
290289
document.execCommand('copy');
291290
document.body.removeChild(textarea);
292291
} catch {
293-
addErrorMessage(lng('modai.cmp.failed_copy'));
292+
addErrorMessage(lng('modai.error.failed_copy'));
294293
}
295294
}
296295
};

_build/js/src/ui/localChat/modalActions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { setLoadingState } from './state';
44
import { chatHistory } from '../../chatHistory';
55
import { executor } from '../../executor';
66
import { globalState } from '../../globalState';
7+
import { lng } from '../../lng';
78

89
import type { LocalChatConfig, ModalType } from './types';
910
import type { Prompt } from '../../executor';
@@ -104,7 +105,7 @@ export const sendMessage = async (
104105
return;
105106
}
106107

107-
addErrorMessage('Unknown error');
108+
addErrorMessage(lng('modai.error.unknown_error'));
108109
}
109110

110111
setLoadingState(false);
@@ -188,7 +189,7 @@ export const clearChat = () => {
188189

189190
export const handleImageUpload = async (fileOrUrl: File | string, isRemoteUrl: boolean = false) => {
190191
if (!isRemoteUrl && fileOrUrl instanceof File && !fileOrUrl.type.startsWith('image/')) {
191-
addErrorMessage('Only image files are allowed');
192+
addErrorMessage(lng('modai.error.only_image_files_are_allowed'));
192193
return;
193194
}
194195

_build/js/src/ui/localChat/modalBuilder.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { buildModalHeader } from './modalHeader';
66
import { buildModalInput } from './modalInput';
77
import { chatHistory } from '../../chatHistory';
88
import { globalState } from '../../globalState';
9+
import { lng } from '../../lng';
910
import { createModAIShadow } from '../dom/modAIShadow';
1011

1112
import type { Modal, LocalChatConfig } from './types';
@@ -17,7 +18,7 @@ export const buildModal = (config: LocalChatConfig) => {
1718
});
1819

1920
const chatModal = createElement('div', 'modai--root chat-modal', '', {
20-
ariaLabel: 'modAI Assistant chat dialog',
21+
ariaLabel: lng('modai.ui.modai_assistant_chat_dialog'),
2122
});
2223

2324
shadow.modal = chatModal;
@@ -31,11 +32,7 @@ export const buildModal = (config: LocalChatConfig) => {
3132
chatModal.append(buildModalChat());
3233
chatModal.append(buildModalInput(config));
3334

34-
const disclaimer = createElement(
35-
'div',
36-
'disclaimer',
37-
'AI can make mistakes. Please double-check responses.',
38-
);
35+
const disclaimer = createElement('div', 'disclaimer', lng('modai.ui.disclaimer'));
3936
chatModal.append(disclaimer);
4037

4138
shadowRoot.appendChild(chatModal);

_build/js/src/ui/localChat/modalChat.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { globalState } from '../../globalState';
2+
import { lng } from '../../lng';
23
import { createElement } from '../utils';
34

45
export const buildModalChat = () => {
@@ -10,15 +11,17 @@ export const buildModalChat = () => {
1011
createElement(
1112
'p',
1213
'greeting',
13-
globalState.config.name ? `Welcome, ${globalState.config.name}.` : 'Welcome!',
14+
globalState.config.name
15+
? lng('modai.ui.greeting_with_name', { name: globalState.config.name })
16+
: lng('modai.ui.greeting'),
1417
),
15-
createElement('p', 'msg', 'How can I help you today? ✨'),
18+
createElement('p', 'msg', lng('modai.ui.welcome_msg')),
1619
]);
1720

1821
chatContainer.append(welcome);
1922

2023
const chatHistory = createElement('div', 'history', '', {
21-
ariaLabel: 'Conversation history',
24+
ariaLabel: lng('modai.ui.conversation_history'),
2225
});
2326
chatContainer.append(chatHistory);
2427

0 commit comments

Comments
 (0)