First version running with npm run dev
This commit is contained in:
commit
f90ec06a4f
28 files changed
+12042
No files matched your search
+24
@@ -0,0 +1,24 @@
|
|||||||
|
# Nuxt dev/build outputs
|
||||||
|
.output
|
||||||
|
.data
|
||||||
|
.nuxt
|
||||||
|
.nitro
|
||||||
|
.cache
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Node dependencies
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
.fleet
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Local env files
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<script setup lang="ts"></script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<NuxtLayout>
|
||||||
|
<NuxtPage />
|
||||||
|
</NuxtLayout>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
:root {
|
||||||
|
--primary-color: #42b883;
|
||||||
|
--secondary-color: #35495e;
|
||||||
|
--bg-color: #ffffff;
|
||||||
|
--text-color: #2c3e50;
|
||||||
|
--border-color: #e0e0e0;
|
||||||
|
--error-color: #e74c3c;
|
||||||
|
--success-color: #27ae60;
|
||||||
|
--surface-color: #ffffff;
|
||||||
|
--surface-alt-color: #f8f9fa;
|
||||||
|
--muted-color: #666;
|
||||||
|
--placeholder-color: #999;
|
||||||
|
--stat-bg-color: #f0f0f0;
|
||||||
|
--clear-btn-color: #95a5a6;
|
||||||
|
--banner-warning-bg: #fff3cd;
|
||||||
|
--banner-warning-border: #ffc107;
|
||||||
|
--banner-warning-text: #856404;
|
||||||
|
--banner-error-bg: #f8d7da;
|
||||||
|
--banner-error-border: #f5c6cb;
|
||||||
|
--banner-error-text: #721c24;
|
||||||
|
--overlay-color: rgba(0, 0, 0, 0.5);
|
||||||
|
--modal-bg: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] {
|
||||||
|
--primary-color: #42d392;
|
||||||
|
--secondary-color: #1a2332;
|
||||||
|
--bg-color: #0f1923;
|
||||||
|
--text-color: #e0e6ed;
|
||||||
|
--border-color: #2a3a4a;
|
||||||
|
--error-color: #ff6b6b;
|
||||||
|
--success-color: #51cf88;
|
||||||
|
--surface-color: #1a2836;
|
||||||
|
--surface-alt-color: #1e2f3d;
|
||||||
|
--muted-color: #8899aa;
|
||||||
|
--placeholder-color: #5a6a7a;
|
||||||
|
--stat-bg-color: #1e2f3d;
|
||||||
|
--clear-btn-color: #5a6a7a;
|
||||||
|
--banner-warning-bg: #332b00;
|
||||||
|
--banner-warning-border: #665500;
|
||||||
|
--banner-warning-text: #ffd54f;
|
||||||
|
--banner-error-bg: #3b1a1a;
|
||||||
|
--banner-error-border: #5a2a2a;
|
||||||
|
--banner-error-text: #ff8a8a;
|
||||||
|
--overlay-color: rgba(0, 0, 0, 0.7);
|
||||||
|
--modal-bg: #1a2836;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family:
|
||||||
|
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
|
||||||
|
Cantarell, sans-serif;
|
||||||
|
background-color: var(--bg-color);
|
||||||
|
color: var(--text-color);
|
||||||
|
line-height: 1.6;
|
||||||
|
transition:
|
||||||
|
background-color 0.3s,
|
||||||
|
color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition:
|
||||||
|
opacity 0.2s,
|
||||||
|
background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input,
|
||||||
|
.textarea,
|
||||||
|
.select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-family: inherit;
|
||||||
|
background-color: var(--surface-color);
|
||||||
|
color: var(--text-color);
|
||||||
|
transition:
|
||||||
|
border-color 0.3s,
|
||||||
|
background-color 0.3s,
|
||||||
|
color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input:focus,
|
||||||
|
.textarea:focus,
|
||||||
|
.select:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background: var(--surface-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
margin: 1rem 0;
|
||||||
|
transition:
|
||||||
|
background-color 0.3s,
|
||||||
|
border-color 0.3s;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useLanguages } from "~/composables/useLanguages";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
label?: string;
|
||||||
|
modelValue: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: "update:modelValue", value: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { languages } = useLanguages();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="language-selector">
|
||||||
|
<label v-if="props.label" class="language-selector-label">
|
||||||
|
{{ props.label }}
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
class="language-selector-input select"
|
||||||
|
:value="props.modelValue"
|
||||||
|
@change="
|
||||||
|
emit('update:modelValue', ($event.target as HTMLSelectElement).value)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<option v-for="lang in languages" :key="lang.code" :value="lang.code">
|
||||||
|
{{ lang.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.language-selector {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.language-selector-label {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.language-selector-input {
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
interface Props {
|
||||||
|
visible: boolean;
|
||||||
|
currentModel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: "update:visible", value: boolean): void;
|
||||||
|
(e: "update:currentModel", value: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const MODEL_OPTIONS = [
|
||||||
|
{
|
||||||
|
value: "translategemma:1b",
|
||||||
|
label: "TranslateGemma 1B",
|
||||||
|
description: "Faster, lower quality (~2GB VRAM)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "translategemma:2b",
|
||||||
|
label: "TranslateGemma 2B",
|
||||||
|
description: "Balanced speed/quality (~3GB VRAM)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "translategemma:4b",
|
||||||
|
label: "TranslateGemma 4B",
|
||||||
|
description: "Best quality (~4GB VRAM)",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const selectedModel = ref(props.currentModel);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.currentModel,
|
||||||
|
(val) => {
|
||||||
|
selectedModel.value = val;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.visible,
|
||||||
|
(val) => {
|
||||||
|
if (val) {
|
||||||
|
selectedModel.value = props.currentModel;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
emit("update:currentModel", selectedModel.value);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
emit("update:visible", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOverlayClick(event: MouseEvent) {
|
||||||
|
if ((event.target as HTMLElement).classList.contains("settings-overlay")) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
document.addEventListener("keydown", handleKeydown);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
document.removeEventListener("keydown", handleKeydown);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<Transition name="modal">
|
||||||
|
<div v-if="visible" class="settings-overlay" @click="handleOverlayClick">
|
||||||
|
<div
|
||||||
|
class="settings-modal"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
aria-label="Settings"
|
||||||
|
>
|
||||||
|
<div class="settings-header">
|
||||||
|
<h2 class="settings-title">Settings</h2>
|
||||||
|
<button
|
||||||
|
class="settings-close"
|
||||||
|
@click="close"
|
||||||
|
type="button"
|
||||||
|
aria-label="Close settings"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settings-body">
|
||||||
|
<div class="setting-group">
|
||||||
|
<label class="setting-label">Translation Model</label>
|
||||||
|
<p class="setting-description">
|
||||||
|
Choose the model size for translation quality vs speed.
|
||||||
|
</p>
|
||||||
|
<div class="model-options">
|
||||||
|
<label
|
||||||
|
v-for="option in MODEL_OPTIONS"
|
||||||
|
:key="option.value"
|
||||||
|
class="model-option"
|
||||||
|
:class="{ selected: selectedModel === option.value }"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
:value="option.value"
|
||||||
|
v-model="selectedModel"
|
||||||
|
class="model-radio"
|
||||||
|
/>
|
||||||
|
<div class="model-info">
|
||||||
|
<span class="model-name">{{ option.label }}</span>
|
||||||
|
<span class="model-desc">{{ option.description }}</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settings-footer">
|
||||||
|
<button
|
||||||
|
class="btn settings-cancel-btn"
|
||||||
|
@click="close"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button class="btn settings-save-btn" @click="save" type="button">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.settings-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background-color: var(--overlay-color);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 9000;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-modal {
|
||||||
|
background-color: var(--modal-bg);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 12px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 480px;
|
||||||
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 1.25rem 1.5rem;
|
||||||
|
border-bottom: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-close {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--muted-color);
|
||||||
|
padding: 0.25rem;
|
||||||
|
line-height: 1;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-close:hover {
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-body {
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-label {
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.9375rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-description {
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
color: var(--muted-color);
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-options {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-option {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
border-color 0.2s,
|
||||||
|
background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-option:hover {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-option.selected {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
background-color: var(--surface-alt-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-radio {
|
||||||
|
accent-color: var(--primary-color);
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-name {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.9375rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.model-desc {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
border-top: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-cancel-btn {
|
||||||
|
background-color: var(--clear-btn-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.settings-save-btn {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-enter-active {
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-enter-active .settings-modal {
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-leave-active {
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-leave-active .settings-modal {
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-enter-from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-enter-from .settings-modal {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-leave-to .settings-modal {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.settings-modal {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
interface Props {
|
||||||
|
label?: string;
|
||||||
|
modelValue: string;
|
||||||
|
placeholder?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
minRows?: number;
|
||||||
|
maxRows?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
placeholder: "Enter text to translate...",
|
||||||
|
disabled: false,
|
||||||
|
minRows: 3,
|
||||||
|
maxRows: 12,
|
||||||
|
});
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: "update:modelValue", value: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const textareaRef = ref<HTMLTextAreaElement | null>(null);
|
||||||
|
|
||||||
|
function autoResize() {
|
||||||
|
const textarea = textareaRef.value;
|
||||||
|
if (!textarea) return;
|
||||||
|
|
||||||
|
textarea.style.height = "auto";
|
||||||
|
textarea.style.height = `${textarea.scrollHeight}px`;
|
||||||
|
|
||||||
|
const style = getComputedStyle(textarea);
|
||||||
|
const lineHeight = parseFloat(style.lineHeight) || 24;
|
||||||
|
const minRows = props.minRows * lineHeight;
|
||||||
|
const maxRows = props.maxRows * lineHeight;
|
||||||
|
|
||||||
|
const currentHeight = textarea.scrollHeight;
|
||||||
|
if (currentHeight < minRows) {
|
||||||
|
textarea.style.height = `${minRows}px`;
|
||||||
|
} else if (currentHeight > maxRows) {
|
||||||
|
textarea.style.height = `${maxRows}px`;
|
||||||
|
textarea.style.overflowY = "auto";
|
||||||
|
} else {
|
||||||
|
textarea.style.overflowY = "hidden";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInput(event: Event) {
|
||||||
|
const target = event.target as HTMLTextAreaElement;
|
||||||
|
emit("update:modelValue", target.value);
|
||||||
|
autoResize();
|
||||||
|
}
|
||||||
|
|
||||||
|
const charCount = computed(() => props.modelValue.length);
|
||||||
|
const wordCount = computed(() => {
|
||||||
|
const text = props.modelValue.trim();
|
||||||
|
return text ? text.split(/\s+/).length : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
() => {
|
||||||
|
nextTick(autoResize);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="text-input">
|
||||||
|
<label v-if="props.label" class="text-input-label">
|
||||||
|
{{ props.label }}
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
ref="textareaRef"
|
||||||
|
class="text-input-area textarea"
|
||||||
|
:value="props.modelValue"
|
||||||
|
:placeholder="props.placeholder"
|
||||||
|
:disabled="props.disabled"
|
||||||
|
:rows="minRows"
|
||||||
|
@input="handleInput"
|
||||||
|
/>
|
||||||
|
<div class="text-input-stats">
|
||||||
|
<span class="stat">{{ wordCount }} words</span>
|
||||||
|
<span class="stat">{{ charCount }} characters</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.text-input {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-input-label {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-input-area {
|
||||||
|
min-height: calc(24px * 3);
|
||||||
|
font-size: 1rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
resize: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-input-stats {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat {
|
||||||
|
background: var(--stat-bg-color);
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useTheme } from "~/composables/useTheme";
|
||||||
|
|
||||||
|
const { theme, toggleTheme } = useTheme();
|
||||||
|
|
||||||
|
const label = computed(() =>
|
||||||
|
theme.value === "dark" ? "Switch to light mode" : "Switch to dark mode",
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<button
|
||||||
|
class="theme-toggle"
|
||||||
|
@click="toggleTheme"
|
||||||
|
type="button"
|
||||||
|
:aria-label="label"
|
||||||
|
:title="label"
|
||||||
|
>
|
||||||
|
<span v-if="theme === 'dark'" class="theme-icon">☼</span>
|
||||||
|
<span v-else class="theme-icon">☾</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.theme-toggle {
|
||||||
|
background: none;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
line-height: 1;
|
||||||
|
transition:
|
||||||
|
border-color 0.2s,
|
||||||
|
background-color 0.2s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-toggle:hover {
|
||||||
|
border-color: rgba(255, 255, 255, 0.6);
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-icon {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useToast } from "~/composables/useToast";
|
||||||
|
|
||||||
|
const { toasts, dismiss } = useToast();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Teleport to="body">
|
||||||
|
<div class="toast-container" aria-live="polite">
|
||||||
|
<TransitionGroup name="toast">
|
||||||
|
<div
|
||||||
|
v-for="toast in toasts"
|
||||||
|
:key="toast.id"
|
||||||
|
class="toast"
|
||||||
|
:class="`toast--${toast.type}`"
|
||||||
|
@click="dismiss(toast.id)"
|
||||||
|
role="status"
|
||||||
|
>
|
||||||
|
<span class="toast-icon">
|
||||||
|
<template v-if="toast.type === 'success'">✓</template>
|
||||||
|
<template v-else-if="toast.type === 'error'">✗</template>
|
||||||
|
<template v-else>ⓘ</template>
|
||||||
|
</span>
|
||||||
|
<span class="toast-message">{{ toast.message }}</span>
|
||||||
|
</div>
|
||||||
|
</TransitionGroup>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.toast-container {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 1.5rem;
|
||||||
|
right: 1.5rem;
|
||||||
|
z-index: 9999;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
gap: 0.5rem;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
color: white;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
pointer-events: auto;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
max-width: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast--success {
|
||||||
|
background-color: var(--success-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast--error {
|
||||||
|
background-color: var(--error-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast--info {
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-message {
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-enter-active,
|
||||||
|
.toast-leave-active {
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-enter-from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(1rem);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(1rem);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useToast } from "~/composables/useToast";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
label?: string;
|
||||||
|
text: string;
|
||||||
|
loading?: boolean;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: "copy"): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { show: showToast } = useToast();
|
||||||
|
const isCopied = ref(false);
|
||||||
|
|
||||||
|
async function copyToClipboard() {
|
||||||
|
if (!props.text) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(props.text);
|
||||||
|
isCopied.value = true;
|
||||||
|
emit("copy");
|
||||||
|
showToast("Copied to clipboard", "success");
|
||||||
|
setTimeout(() => {
|
||||||
|
isCopied.value = false;
|
||||||
|
}, 2000);
|
||||||
|
} catch {
|
||||||
|
isCopied.value = false;
|
||||||
|
showToast("Failed to copy text", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputRef = computed(() => props.text);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="translation-output">
|
||||||
|
<div class="translation-output-header">
|
||||||
|
<label v-if="label" class="translation-output-label">
|
||||||
|
{{ label }}
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
v-if="outputRef"
|
||||||
|
class="copy-btn btn"
|
||||||
|
@click="copyToClipboard"
|
||||||
|
:disabled="loading"
|
||||||
|
type="button"
|
||||||
|
:aria-label="isCopied ? 'Copied!' : 'Copy to clipboard'"
|
||||||
|
:title="isCopied ? 'Copied!' : 'Copy to clipboard'"
|
||||||
|
>
|
||||||
|
{{ isCopied ? "✓ Copied" : "Copy" }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="translation-output-area textarea"
|
||||||
|
:class="{ loading: loading, error: !!error }"
|
||||||
|
>
|
||||||
|
<div v-if="loading" class="translation-loading">
|
||||||
|
<div class="loading-spinner"></div>
|
||||||
|
<span>Translating...</span>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="error" class="translation-error">
|
||||||
|
<span class="error-icon">⚠</span>
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
<div v-else-if="text" class="translation-result">
|
||||||
|
{{ text }}
|
||||||
|
</div>
|
||||||
|
<span v-else class="translation-placeholder">
|
||||||
|
Translation will appear here...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.translation-output {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-output-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-output-label {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn {
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-output-area {
|
||||||
|
position: relative;
|
||||||
|
min-height: 120px;
|
||||||
|
background-color: var(--surface-alt-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-output-area.loading {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-loading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
color: var(--muted-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spinner {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid var(--border-color);
|
||||||
|
border-top-color: var(--primary-color);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-error {
|
||||||
|
color: var(--error-color);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-icon {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-placeholder {
|
||||||
|
color: var(--placeholder-color);
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { ref, computed } from "vue";
|
||||||
|
import type { Language } from "~/types/translation";
|
||||||
|
import { supportedLanguages, getLanguageByCode } from "~/utils/languages";
|
||||||
|
|
||||||
|
export function useLanguages() {
|
||||||
|
const languages = ref<Language[]>(supportedLanguages);
|
||||||
|
const searchQuery = ref("");
|
||||||
|
|
||||||
|
const filteredLanguages = computed(() => {
|
||||||
|
if (!searchQuery.value.trim()) {
|
||||||
|
return languages.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = searchQuery.value.toLowerCase();
|
||||||
|
return languages.value.filter(
|
||||||
|
(lang) =>
|
||||||
|
lang.name.toLowerCase().includes(query) ||
|
||||||
|
lang.nativeName?.toLowerCase().includes(query) ||
|
||||||
|
lang.code.toLowerCase().includes(query),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const getLanguageName = (code: string): string => {
|
||||||
|
const lang = getLanguageByCode(code);
|
||||||
|
return lang?.name || code;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLanguageNativeName = (code: string): string => {
|
||||||
|
const lang = getLanguageByCode(code);
|
||||||
|
return lang?.nativeName || lang?.name || code;
|
||||||
|
};
|
||||||
|
|
||||||
|
const search = (query: string) => {
|
||||||
|
searchQuery.value = query;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearSearch = () => {
|
||||||
|
searchQuery.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
languages,
|
||||||
|
filteredLanguages,
|
||||||
|
searchQuery,
|
||||||
|
search,
|
||||||
|
clearSearch,
|
||||||
|
getLanguageName,
|
||||||
|
getLanguageNativeName,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import { ref, computed, onMounted } from "vue";
|
||||||
|
|
||||||
|
interface OllamaStatus {
|
||||||
|
available: boolean;
|
||||||
|
running: boolean;
|
||||||
|
modelExists: boolean;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useOllamaStatus() {
|
||||||
|
const status = ref<OllamaStatus>({
|
||||||
|
available: false,
|
||||||
|
running: false,
|
||||||
|
modelExists: false,
|
||||||
|
message: "Checking Ollama status...",
|
||||||
|
});
|
||||||
|
|
||||||
|
const isLoading = ref(true);
|
||||||
|
const isChecking = ref(false);
|
||||||
|
|
||||||
|
async function checkStatus() {
|
||||||
|
isChecking.value = true;
|
||||||
|
isLoading.value = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/tags", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
status.value = {
|
||||||
|
available: false,
|
||||||
|
running: false,
|
||||||
|
modelExists: false,
|
||||||
|
message: "Ollama service is not running",
|
||||||
|
};
|
||||||
|
isLoading.value = false;
|
||||||
|
isChecking.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
status.value = {
|
||||||
|
available: data.available,
|
||||||
|
running: data.running,
|
||||||
|
modelExists: data.modelExists,
|
||||||
|
message: data.modelExists
|
||||||
|
? "Ollama is ready"
|
||||||
|
: `Model "${data.model}" not found. Run: ollama pull ${data.model}`,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
status.value = {
|
||||||
|
available: false,
|
||||||
|
running: false,
|
||||||
|
modelExists: false,
|
||||||
|
message:
|
||||||
|
"Cannot connect to Ollama. Ensure it is running on the configured host.",
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
isChecking.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isReady = computed(
|
||||||
|
() => status.value.available && status.value.modelExists,
|
||||||
|
);
|
||||||
|
|
||||||
|
const errorMessage = computed(() =>
|
||||||
|
status.value.modelExists && status.value.available
|
||||||
|
? null
|
||||||
|
: status.value.message,
|
||||||
|
);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
checkStatus();
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
status,
|
||||||
|
isLoading,
|
||||||
|
isChecking,
|
||||||
|
isReady,
|
||||||
|
errorMessage,
|
||||||
|
checkStatus,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
|
||||||
|
const STORAGE_KEY = "quick-ling-settings";
|
||||||
|
const DEFAULT_MODEL = "translategemma:4b";
|
||||||
|
|
||||||
|
interface Settings {
|
||||||
|
model: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const model = ref(DEFAULT_MODEL);
|
||||||
|
|
||||||
|
function loadSettings(): void {
|
||||||
|
if (typeof localStorage !== "undefined") {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
|
if (stored) {
|
||||||
|
const parsed: Settings = JSON.parse(stored);
|
||||||
|
if (parsed.model) {
|
||||||
|
model.value = parsed.model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore parse errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveSettings(): void {
|
||||||
|
if (typeof localStorage !== "undefined") {
|
||||||
|
const settings: Settings = { model: model.value };
|
||||||
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSettings() {
|
||||||
|
function setModel(newModel: string): void {
|
||||||
|
model.value = newModel;
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadSettings();
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
model,
|
||||||
|
setModel,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { ref, watch, onMounted } from 'vue';
|
||||||
|
|
||||||
|
type Theme = 'light' | 'dark';
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'quick-ling-theme';
|
||||||
|
|
||||||
|
const theme = ref<Theme>('light');
|
||||||
|
|
||||||
|
function applyTheme(t: Theme): void {
|
||||||
|
if (typeof document !== 'undefined') {
|
||||||
|
document.documentElement.setAttribute('data-theme', t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSystemPreference(): Theme {
|
||||||
|
if (typeof window !== 'undefined' && window.matchMedia) {
|
||||||
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||||
|
}
|
||||||
|
return 'light';
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadSavedTheme(): Theme | null {
|
||||||
|
if (typeof localStorage !== 'undefined') {
|
||||||
|
const saved = localStorage.getItem(STORAGE_KEY);
|
||||||
|
if (saved === 'light' || saved === 'dark') {
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveTheme(t: Theme): void {
|
||||||
|
if (typeof localStorage !== 'undefined') {
|
||||||
|
localStorage.setItem(STORAGE_KEY, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTheme() {
|
||||||
|
function toggleTheme(): void {
|
||||||
|
theme.value = theme.value === 'light' ? 'dark' : 'light';
|
||||||
|
}
|
||||||
|
|
||||||
|
function setTheme(t: Theme): void {
|
||||||
|
theme.value = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(theme, (newTheme) => {
|
||||||
|
applyTheme(newTheme);
|
||||||
|
saveTheme(newTheme);
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const saved = loadSavedTheme();
|
||||||
|
const initial = saved ?? getSystemPreference();
|
||||||
|
theme.value = initial;
|
||||||
|
applyTheme(initial);
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined' && window.matchMedia) {
|
||||||
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
mediaQuery.addEventListener('change', (e) => {
|
||||||
|
if (!loadSavedTheme()) {
|
||||||
|
theme.value = e.matches ? 'dark' : 'light';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
theme,
|
||||||
|
toggleTheme,
|
||||||
|
setTheme,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
interface Toast {
|
||||||
|
id: number;
|
||||||
|
message: string;
|
||||||
|
type: "success" | "error" | "info";
|
||||||
|
}
|
||||||
|
|
||||||
|
const toasts = ref<Toast[]>([]);
|
||||||
|
let nextId = 0;
|
||||||
|
|
||||||
|
export function useToast() {
|
||||||
|
function show(
|
||||||
|
message: string,
|
||||||
|
type: Toast["type"] = "success",
|
||||||
|
duration = 2500,
|
||||||
|
): void {
|
||||||
|
const id = nextId++;
|
||||||
|
toasts.value.push({ id, message, type });
|
||||||
|
setTimeout(() => {
|
||||||
|
dismiss(id);
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dismiss(id: number): void {
|
||||||
|
const index = toasts.value.findIndex((t) => t.id === id);
|
||||||
|
if (index !== -1) {
|
||||||
|
toasts.value.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
toasts,
|
||||||
|
show,
|
||||||
|
dismiss,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
import { ref, computed } from "vue";
|
||||||
|
import type { Ref } from "vue";
|
||||||
|
import type { TranslationResponse } from "~/types/translation";
|
||||||
|
import { supportedLanguages } from "~/utils/languages";
|
||||||
|
|
||||||
|
interface UseTranslationOptions {
|
||||||
|
initialSource?: string;
|
||||||
|
initialTarget?: string;
|
||||||
|
model?: Ref<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function detectBrowserLanguage(): string {
|
||||||
|
if (typeof navigator !== "undefined") {
|
||||||
|
const browserLang = navigator.language.toLowerCase();
|
||||||
|
const langCode = browserLang.split("-")[0];
|
||||||
|
|
||||||
|
const matchedLang = supportedLanguages.find(
|
||||||
|
(lang) => lang.code === langCode,
|
||||||
|
);
|
||||||
|
if (matchedLang) {
|
||||||
|
return matchedLang.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browserLang.startsWith("en")) {
|
||||||
|
return "en";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "en";
|
||||||
|
}
|
||||||
|
|
||||||
|
const detectedLang = detectBrowserLanguage();
|
||||||
|
const defaultSource = detectedLang;
|
||||||
|
const defaultTarget = detectedLang === "en" ? "es" : "en";
|
||||||
|
|
||||||
|
export function useTranslation(options: UseTranslationOptions = {}) {
|
||||||
|
const sourceText = ref("");
|
||||||
|
const translatedText = ref("");
|
||||||
|
const sourceLang = ref(options.initialSource || defaultSource);
|
||||||
|
const targetLang = ref(options.initialTarget || defaultTarget);
|
||||||
|
const isLoading = ref(false);
|
||||||
|
const error = ref<string | null>(null);
|
||||||
|
const charCount = computed(() => sourceText.value.length);
|
||||||
|
const wordCount = computed(() => {
|
||||||
|
const text = sourceText.value.trim();
|
||||||
|
return text ? text.split(/\s+/).length : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const isReadyToTranslate = computed(() => {
|
||||||
|
return sourceText.value.trim().length > 0 && !isLoading.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function translate() {
|
||||||
|
if (!isReadyToTranslate.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
translatedText.value = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/translate", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
text: sourceText.value,
|
||||||
|
source: sourceLang.value,
|
||||||
|
target: targetLang.value,
|
||||||
|
...(options.model ? { model: options.model.value } : {}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorBody = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errorBody.statusMessage || "Translation request failed",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: TranslationResponse = await response.json();
|
||||||
|
translatedText.value = result.translatedText;
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Error) {
|
||||||
|
error.value = e.message;
|
||||||
|
} else {
|
||||||
|
error.value = "An unknown error occurred";
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function translateWithStreaming(
|
||||||
|
options: {
|
||||||
|
onChunk?: (chunk: string) => void;
|
||||||
|
onComplete?: (fullText: string) => void;
|
||||||
|
} = {},
|
||||||
|
) {
|
||||||
|
if (!isReadyToTranslate.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
error.value = null;
|
||||||
|
translatedText.value = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/translate-stream", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
text: sourceText.value,
|
||||||
|
source: sourceLang.value,
|
||||||
|
target: targetLang.value,
|
||||||
|
...(options.model ? { model: options.model.value } : {}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorBody = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errorBody.statusMessage || "Streaming translation request failed",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.body) {
|
||||||
|
throw new Error("No response body");
|
||||||
|
}
|
||||||
|
|
||||||
|
const reader = response.body.getReader();
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
let accumulatedText = "";
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
|
||||||
|
const chunk = decoder.decode(value);
|
||||||
|
const lines = chunk.split("\n").filter((line) => line.trim());
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(line);
|
||||||
|
if (parsed.response) {
|
||||||
|
accumulatedText += parsed.response;
|
||||||
|
translatedText.value = accumulatedText;
|
||||||
|
options.onChunk?.(parsed.response);
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
options.onComplete?.(accumulatedText);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof Error) {
|
||||||
|
error.value = e.message;
|
||||||
|
} else {
|
||||||
|
error.value = "An unknown error occurred";
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function swapLanguages() {
|
||||||
|
const temp = sourceLang.value;
|
||||||
|
sourceLang.value = targetLang.value;
|
||||||
|
targetLang.value = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearInput() {
|
||||||
|
sourceText.value = "";
|
||||||
|
translatedText.value = "";
|
||||||
|
error.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sourceText,
|
||||||
|
translatedText,
|
||||||
|
sourceLang,
|
||||||
|
targetLang,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
charCount,
|
||||||
|
wordCount,
|
||||||
|
isReadyToTranslate,
|
||||||
|
translate,
|
||||||
|
translateWithStreaming,
|
||||||
|
swapLanguages,
|
||||||
|
clearInput,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import ThemeToggle from "~/components/ThemeToggle.vue";
|
||||||
|
import SettingsModal from "~/components/SettingsModal.vue";
|
||||||
|
import ToastNotification from "~/components/ToastNotification.vue";
|
||||||
|
import { useTheme } from "~/composables/useTheme";
|
||||||
|
import { useSettings } from "~/composables/useSettings";
|
||||||
|
|
||||||
|
useTheme();
|
||||||
|
const { model, setModel } = useSettings();
|
||||||
|
|
||||||
|
const showSettings = ref(false);
|
||||||
|
|
||||||
|
function handleModelUpdate(newModel: string) {
|
||||||
|
setModel(newModel);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="app-layout">
|
||||||
|
<header class="app-header">
|
||||||
|
<div class="container header-container">
|
||||||
|
<div class="header-text">
|
||||||
|
<h1 class="app-title">Quick Ling</h1>
|
||||||
|
<p class="app-subtitle">Fast Translation with translategemma</p>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<button
|
||||||
|
class="header-btn"
|
||||||
|
@click="showSettings = true"
|
||||||
|
type="button"
|
||||||
|
aria-label="Open settings"
|
||||||
|
title="Settings"
|
||||||
|
>
|
||||||
|
⚙
|
||||||
|
</button>
|
||||||
|
<ThemeToggle />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main class="app-main">
|
||||||
|
<div class="container">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<footer class="app-footer">
|
||||||
|
<div class="container">
|
||||||
|
<p>Powered by translategemma • Ollama</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<SettingsModal
|
||||||
|
:visible="showSettings"
|
||||||
|
:current-model="model"
|
||||||
|
@update:visible="showSettings = $event"
|
||||||
|
@update:current-model="handleModelUpdate"
|
||||||
|
/>
|
||||||
|
<ToastNotification />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.app-layout {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-header {
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
color: white;
|
||||||
|
padding: 2rem 0;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-container {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-text {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-title {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-subtitle {
|
||||||
|
font-size: 1rem;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-btn {
|
||||||
|
background: none;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
line-height: 1;
|
||||||
|
transition:
|
||||||
|
border-color 0.2s,
|
||||||
|
background-color 0.2s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-btn:hover {
|
||||||
|
border-color: rgba(255, 255, 255, 0.6);
|
||||||
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-main {
|
||||||
|
flex: 1;
|
||||||
|
padding: 2rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-footer {
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
padding: 1rem 0;
|
||||||
|
margin-top: auto;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.app-title {
|
||||||
|
font-size: 1.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-subtitle {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import LanguageSelector from "~/components/LanguageSelector.vue";
|
||||||
|
import TextInput from "~/components/TextInput.vue";
|
||||||
|
import TranslationOutput from "~/components/TranslationOutput.vue";
|
||||||
|
import { useTranslation } from "~/composables/useTranslation";
|
||||||
|
import { useOllamaStatus } from "~/composables/useOllamaStatus";
|
||||||
|
import { useSettings } from "~/composables/useSettings";
|
||||||
|
|
||||||
|
const { model } = useSettings();
|
||||||
|
const {
|
||||||
|
sourceText,
|
||||||
|
translatedText,
|
||||||
|
sourceLang,
|
||||||
|
targetLang,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
translate,
|
||||||
|
swapLanguages,
|
||||||
|
clearInput,
|
||||||
|
} = useTranslation({ model });
|
||||||
|
|
||||||
|
const { status, isReady, errorMessage, checkStatus } = useOllamaStatus();
|
||||||
|
|
||||||
|
function handleTranslate() {
|
||||||
|
if (!isReady.value) {
|
||||||
|
error.value = errorMessage.value || "Ollama service is not ready";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.ctrlKey && event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
handleTranslate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="translation-page">
|
||||||
|
<div
|
||||||
|
v-if="!isReady"
|
||||||
|
class="status-banner"
|
||||||
|
:class="status.modelExists ? 'status-warning' : 'status-error'"
|
||||||
|
>
|
||||||
|
<div class="status-content">
|
||||||
|
<span class="status-icon">{{ status.modelExists ? "⚠" : "❌" }}</span>
|
||||||
|
<span class="status-message">{{ status.message }}</span>
|
||||||
|
<button
|
||||||
|
v-if="!status.available"
|
||||||
|
class="btn status-btn"
|
||||||
|
@click="checkStatus"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="translation-controls">
|
||||||
|
<div class="language-selectors">
|
||||||
|
<LanguageSelector label="Translate from" v-model="sourceLang" />
|
||||||
|
<button
|
||||||
|
class="swap-button btn"
|
||||||
|
@click="swapLanguages"
|
||||||
|
type="button"
|
||||||
|
aria-label="Swap languages"
|
||||||
|
title="Swap languages"
|
||||||
|
>
|
||||||
|
⇆
|
||||||
|
</button>
|
||||||
|
<LanguageSelector label="Translate to" v-model="targetLang" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="translation-input">
|
||||||
|
<TextInput
|
||||||
|
label="Source Text"
|
||||||
|
v-model="sourceText"
|
||||||
|
placeholder="Enter text to translate..."
|
||||||
|
:disabled="isLoading"
|
||||||
|
@keydown="handleKeydown"
|
||||||
|
/>
|
||||||
|
<div class="input-actions">
|
||||||
|
<button
|
||||||
|
class="btn clear-btn"
|
||||||
|
@click="clearInput"
|
||||||
|
:disabled="!sourceText"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="btn translate-btn"
|
||||||
|
@click="handleTranslate"
|
||||||
|
:disabled="!sourceText.trim() || isLoading"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{{ isLoading ? "Translating..." : "Translate" }}
|
||||||
|
{{ isLoading || !sourceLang ? "" : "(Ctrl+Enter)" }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="translation-output-section">
|
||||||
|
<TranslationOutput
|
||||||
|
label="Translation"
|
||||||
|
:text="translatedText"
|
||||||
|
:loading="isLoading"
|
||||||
|
:error="error"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.translation-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-controls {
|
||||||
|
background: var(--surface-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
transition:
|
||||||
|
background-color 0.3s,
|
||||||
|
border-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.language-selectors {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swap-button {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
line-height: 1;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-input {
|
||||||
|
background: var(--surface-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
transition:
|
||||||
|
background-color 0.3s,
|
||||||
|
border-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear-btn {
|
||||||
|
background-color: var(--clear-btn-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.translate-btn {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.translation-output-section {
|
||||||
|
background: var(--surface-color);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
transition:
|
||||||
|
background-color 0.3s,
|
||||||
|
border-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-banner {
|
||||||
|
background: var(--banner-warning-bg);
|
||||||
|
border: 1px solid var(--banner-warning-border);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
color: var(--banner-warning-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-banner.status-error {
|
||||||
|
background: var(--banner-error-bg);
|
||||||
|
border-color: var(--banner-error-border);
|
||||||
|
color: var(--banner-error-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-icon {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-message {
|
||||||
|
flex: 1;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-btn {
|
||||||
|
padding: 0.25rem 0.75rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.language-selectors {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.swap-button {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
order: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-actions {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-actions .btn {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-content {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-btn {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
export interface Language {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
nativeName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TranslationRequest {
|
||||||
|
text: string;
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TranslationResponse {
|
||||||
|
translatedText: string;
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
originalText: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OllamaTranslateRequest {
|
||||||
|
model: string;
|
||||||
|
prompt: string;
|
||||||
|
stream: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OllamaTranslateResponse {
|
||||||
|
model: string;
|
||||||
|
created_at: string;
|
||||||
|
response: string;
|
||||||
|
done: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import type { Language } from "~/types/translation";
|
||||||
|
|
||||||
|
export const supportedLanguages: Language[] = [
|
||||||
|
{ code: "en", name: "English", nativeName: "English" },
|
||||||
|
{ code: "es", name: "Spanish", nativeName: "Español" },
|
||||||
|
{ code: "fr", name: "French", nativeName: "Français" },
|
||||||
|
{ code: "de", name: "German", nativeName: "Deutsch" },
|
||||||
|
{ code: "it", name: "Italian", nativeName: "Italiano" },
|
||||||
|
{ code: "pt", name: "Portuguese", nativeName: "Português" },
|
||||||
|
{ code: "nl", name: "Dutch", nativeName: "Nederlands" },
|
||||||
|
{ code: "pl", name: "Polish", nativeName: "Polski" },
|
||||||
|
{ code: "ru", name: "Russian", nativeName: "Русский" },
|
||||||
|
{ code: "ja", name: "Japanese", nativeName: "日本語" },
|
||||||
|
{ code: "zh", name: "Chinese", nativeName: "中文" },
|
||||||
|
{ code: "ko", name: "Korean", nativeName: "한국어" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function getLanguageByCode(code: string): Language | undefined {
|
||||||
|
return supportedLanguages.find((lang) => lang.code === code);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatLanguageCode(
|
||||||
|
sourceCode: string,
|
||||||
|
targetCode: string,
|
||||||
|
): string {
|
||||||
|
return `${sourceCode} → ${targetCode}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
compatibilityDate: '2025-07-15',
|
||||||
|
devtools: { enabled: true },
|
||||||
|
app: {
|
||||||
|
head: {
|
||||||
|
title: 'Quick Ling - Fast Translation',
|
||||||
|
meta: [
|
||||||
|
{ charset: 'utf-8' },
|
||||||
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
|
{ name: 'description', content: 'A fast web application for text translation between languages' }
|
||||||
|
],
|
||||||
|
link: [
|
||||||
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
ollamahost: 'http://localhost:11434',
|
||||||
|
ollamamodel: 'translategemma:4b'
|
||||||
|
},
|
||||||
|
css: ['~/assets/css/main.css']
|
||||||
|
})
|
||||||
Generated
+9732
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "quick-ling",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "nuxt build",
|
||||||
|
"dev": "nuxt dev",
|
||||||
|
"generate": "nuxt generate",
|
||||||
|
"preview": "nuxt preview",
|
||||||
|
"postinstall": "nuxt prepare"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"nuxt": "^4.3.1",
|
||||||
|
"vue": "^3.5.30",
|
||||||
|
"vue-router": "^4.6.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^5.9.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,2 @@
|
|||||||
|
User-Agent: *
|
||||||
|
Disallow:
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { defineEventHandler, createError } from "h3";
|
||||||
|
|
||||||
|
export default defineEventHandler(async () => {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const ollamaUrl = config.ollamahost;
|
||||||
|
const model = config.ollamamodel;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ollamaUrl}/api/tags`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: response.status,
|
||||||
|
statusMessage: "Failed to fetch tags from Ollama",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const models = data.models || [];
|
||||||
|
const modelExists = models.some(
|
||||||
|
(m: { name: string }) => m.name.startsWith(model) || m.name === model,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
available: true,
|
||||||
|
running: true,
|
||||||
|
modelExists,
|
||||||
|
model,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error && "statusCode" in error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw createError({
|
||||||
|
statusCode: 503,
|
||||||
|
statusMessage: "Cannot connect to Ollama service",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import {
|
||||||
|
defineEventHandler,
|
||||||
|
readBody,
|
||||||
|
createError,
|
||||||
|
setResponseHeaders,
|
||||||
|
} from "h3";
|
||||||
|
|
||||||
|
interface TranslateRequestBody {
|
||||||
|
text: string;
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
model?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody<TranslateRequestBody>(event);
|
||||||
|
|
||||||
|
if (!body.text || !body.source || !body.target) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
statusMessage: "Missing required fields: text, source, target",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!body.text.trim()) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
statusMessage: "Text cannot be empty",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const ollamaUrl = config.ollamahost;
|
||||||
|
const ALLOWED_MODELS = [
|
||||||
|
"translategemma:1b",
|
||||||
|
"translategemma:2b",
|
||||||
|
"translategemma:4b",
|
||||||
|
];
|
||||||
|
const model =
|
||||||
|
body.model && ALLOWED_MODELS.includes(body.model)
|
||||||
|
? body.model
|
||||||
|
: config.ollamamodel;
|
||||||
|
|
||||||
|
const prompt = `Translate the following text from ${body.source} to ${body.target}. Only output the translation, nothing else.
|
||||||
|
|
||||||
|
Text to translate: ${body.text}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ollamaUrl}/api/generate`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
stream: true,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorBody = await response.json().catch(() => ({}));
|
||||||
|
const errorMsg = errorBody.error || "Ollama request failed";
|
||||||
|
|
||||||
|
if (
|
||||||
|
errorMsg.includes("model not found") ||
|
||||||
|
errorMsg.includes("does not exist")
|
||||||
|
) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
statusMessage: `Model "${model}" not found. Install it by running: ollama pull ${model}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
throw createError({
|
||||||
|
statusCode: response.status,
|
||||||
|
statusMessage: errorMsg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.body) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 502,
|
||||||
|
statusMessage: "No response body from Ollama",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseHeaders(event, {
|
||||||
|
"Content-Type": "application/x-ndjson",
|
||||||
|
"Transfer-Encoding": "chunked",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.body;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (
|
||||||
|
error.message.includes("ECONNREFUSED") ||
|
||||||
|
error.message.includes("fetch failed")
|
||||||
|
) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 503,
|
||||||
|
statusMessage:
|
||||||
|
"Ollama service is not available. Please ensure Ollama is running on " +
|
||||||
|
ollamaUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ("statusCode" in error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: "Unknown error occurred during streaming translation",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
import { defineEventHandler, readBody, createError } from "h3";
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const requestQueue = new Map<string, { count: number; windowStart: number }>();
|
||||||
|
const RATE_LIMIT_WINDOW = 10000;
|
||||||
|
const MAX_REQUESTS_PER_WINDOW = 5;
|
||||||
|
|
||||||
|
interface TranslateRequestBody {
|
||||||
|
text: string;
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
model?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OllamaRequest {
|
||||||
|
model: string;
|
||||||
|
prompt: string;
|
||||||
|
stream: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface OllamaResponse {
|
||||||
|
model: string;
|
||||||
|
response: string;
|
||||||
|
done: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody<TranslateRequestBody>(event);
|
||||||
|
|
||||||
|
if (!body.text || !body.source || !body.target) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
statusMessage: "Missing required fields: text, source, target",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!body.text.trim()) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 400,
|
||||||
|
statusMessage: "Text cannot be empty",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientIP = getRequestHeader(event, "x-forwarded-for") || "anonymous";
|
||||||
|
const now = Date.now();
|
||||||
|
const clientData = requestQueue.get(clientIP);
|
||||||
|
|
||||||
|
if (clientData && now - clientData.windowStart < RATE_LIMIT_WINDOW) {
|
||||||
|
if (clientData.count >= MAX_REQUESTS_PER_WINDOW) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 429,
|
||||||
|
statusMessage: `Rate limit exceeded. Maximum ${MAX_REQUESTS_PER_WINDOW} requests per ${RATE_LIMIT_WINDOW / 1000} seconds.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
clientData.count++;
|
||||||
|
} else {
|
||||||
|
requestQueue.set(clientIP, { count: 1, windowStart: now });
|
||||||
|
}
|
||||||
|
|
||||||
|
const ollamaUrl = config.ollamahost;
|
||||||
|
const ALLOWED_MODELS = [
|
||||||
|
"translategemma:1b",
|
||||||
|
"translategemma:2b",
|
||||||
|
"translategemma:4b",
|
||||||
|
];
|
||||||
|
const model =
|
||||||
|
body.model && ALLOWED_MODELS.includes(body.model)
|
||||||
|
? body.model
|
||||||
|
: config.ollamamodel;
|
||||||
|
|
||||||
|
const prompt = `Translate the following text from ${body.source} to ${body.target}. Only output the translation, nothing else.
|
||||||
|
|
||||||
|
Text to translate: ${body.text}`;
|
||||||
|
|
||||||
|
const ollamaRequest: OllamaRequest = {
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
stream: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tagsResponse = await fetch(`${ollamaUrl}/api/tags`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tagsResponse.ok) {
|
||||||
|
const tagsData = await tagsResponse.json();
|
||||||
|
const models = tagsData.models || [];
|
||||||
|
const modelExists = models.some(
|
||||||
|
(m: { name: string }) => m.name.startsWith(model) || m.name === model,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!modelExists) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
statusMessage: `Model "${model}" not found. Install it by running: ollama pull ${model}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ollamaUrl}/api/generate`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(ollamaRequest),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorBody = await response.json().catch(() => ({}));
|
||||||
|
const errorMsg = errorBody.error || "Ollama request failed";
|
||||||
|
|
||||||
|
if (
|
||||||
|
errorMsg.includes("model not found") ||
|
||||||
|
errorMsg.includes("does not exist")
|
||||||
|
) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
statusMessage: `Model "${model}" not found. Install it by running: ollama pull ${model}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
throw createError({
|
||||||
|
statusCode: response.status,
|
||||||
|
statusMessage: errorMsg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ollamaResponse: OllamaResponse = await response.json();
|
||||||
|
|
||||||
|
return {
|
||||||
|
translatedText: ollamaResponse.response.trim(),
|
||||||
|
source: body.source,
|
||||||
|
target: body.target,
|
||||||
|
originalText: body.text,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
if (
|
||||||
|
error.message.includes("ECONNREFUSED") ||
|
||||||
|
error.message.includes("fetch failed")
|
||||||
|
) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 503,
|
||||||
|
statusMessage:
|
||||||
|
"Ollama service is not available. Please ensure Ollama is running on " +
|
||||||
|
ollamaUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
error.cause instanceof Error &&
|
||||||
|
error.cause.message.includes("model not found")
|
||||||
|
) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 404,
|
||||||
|
statusMessage: `Model "${model}" not found. Install it by running: ollama pull ${model}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: "Unknown error occurred during translation",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
// https://nuxt.com/docs/guide/concepts/typescript
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.server.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.shared.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./.nuxt/tsconfig.node.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user