Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Węgliński authored and Krzysztof Węgliński committed Jan 17, 2025
1 parent 4ec4c07 commit a24b903
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 49 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NEW:

Support for language tool has been added!
- Support for language tool has been added!
- Ollama for translation has been added!

# Pole Language Frontend

Expand Down Expand Up @@ -29,10 +30,10 @@ Here's a sample docker compose:
pole-libretranslate:
restart: unless-stopped
environment:
LTAPI: https://your.languagetool.instance
API: https://your.libretranslate.instance
LANGUAGE_TOOL: https://your.languagetool.instance
LIBRETRANSLATE: https://your.libretranslate.instance
OLLAMA: https://your.ollama.instance
OLLAMA_MODEL: model_name
OLLAMA_API: https://your.ollama.instance
# pick one of: 'pole' | 'light' | 'dark'
THEME: 'dark'
ports:
Expand Down
9 changes: 9 additions & 0 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ const handleFormDataPost = (url, req, res) => {
});
};

app.get("/api/status", (req, res) => {
res.send({
LANGUAGE_TOOL,
LIBRETRANSLATE,
OLLAMA,
OLLAMA_MODEL,
});
});

app.get("/api/libretranslate/languages", (req, res) => {
handleProxyGET(`${LIBRETRANSLATE}/languages`, res);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sth-libretranslate",
"private": true,
"version": "0.0.0",
"version": "0.5.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
46 changes: 21 additions & 25 deletions src/switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import Box from "@mui/material/Box";
Expand Down Expand Up @@ -35,35 +35,31 @@ function a11yProps(index: number) {
};
}

const hasLangTool = () => {
const urlParams = new URLSearchParams(window.location.search);
const languageCheckerUrl = urlParams.get("ltapi");

const baseUrl =
//@ts-expect-error: window
languageCheckerUrl ?? window._lturl;

return baseUrl !== "%LTAPI%";
};

const hasLibreTanslate = () => {
const urlParams = new URLSearchParams(window.location.search);
const libreUrl = urlParams.get("api");

//@ts-expect-error: window
const baseUrl = libreUrl ?? window._libreurl;

return baseUrl !== "%API%";
};

export const Switcher = () => {
const initTab = parseInt(localStorage.getItem("tab") ?? "0");
const [status, setStatus] = useState({
libreTranslate: false,
languageTool: false,
ollama: false,
});
const [tab, setTab] = useState(initTab);
const tabSetter = (val: number) => {
setTab(val);
localStorage.setItem("tab", val.toString());
};

useEffect(() => {
fetch("/api/status")
.then((data) => data.json())
.then((data) => {
setStatus({
libreTranslate: data.LIBRETRANSLATE,
languageTool: data.LANGUAGE_TOOL,
ollama: data.OLLAMA,
});
});
}, []);

return (
<>
<Box sx={{ borderBottom: 1, borderColor: "divider" }}>
Expand All @@ -73,12 +69,12 @@ export const Switcher = () => {
onChange={(_, val) => tabSetter(val)}
aria-label="basic tabs example"
>
{hasLibreTanslate() && <Tab label="Translate" {...a11yProps(0)} />}
{hasLangTool() && <Tab label="Language Check" {...a11yProps(1)} />}
{status.libreTranslate && <Tab label="Translate" {...a11yProps(0)} />}
{status.languageTool && <Tab label="Language Check" {...a11yProps(1)} />}
</Tabs>
</Box>
<CustomTabPanel value={tab} index={0}>
<Translate />
<Translate ollama={status.ollama} />
</CustomTabPanel>
<CustomTabPanel value={tab} index={1}>
<LangCheck />
Expand Down
3 changes: 2 additions & 1 deletion src/translate/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { API } from "./API";
import { TransBox } from "./TransBox";
import { Lang, LangChoice, TranslationResponse } from "./types";

function App() {
function App({ ollama }: { ollama: boolean }) {
const [loading, setLoading] = useState(false);
const [question, setQuestion] = useState(
localStorage.getItem("question") ?? ""
Expand Down Expand Up @@ -90,6 +90,7 @@ function App() {
setSource={setSource}
target={target}
setTarget={setTarget}
ollama={ollama}
useAi={useAI}
setUseAi={setUseAi}
/>
Expand Down
40 changes: 22 additions & 18 deletions src/translate/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const Settings = ({
setTarget,
useAi,
setUseAi,
ollama,
}: {
languages: Lang[];
source: LangChoice;
Expand All @@ -31,6 +32,7 @@ export const Settings = ({
setTarget: React.Dispatch<React.SetStateAction<unknown>>;
useAi: boolean;
setUseAi: (val: boolean) => void;
ollama: boolean;
}) => {
const targets =
source.code === AUTOMATIC.code
Expand All @@ -45,24 +47,26 @@ export const Settings = ({

return langLoaded ? (
<div>
<FormControlLabel
sx={{ float: "right" }}
control={
<Switch
checked={useAi}
onChange={() => setUseAi(!useAi)}
size="small"
/>
}
label={
<Stack
direction="row"
sx={{ justifyContent: "center", alignItems: "center" }}
>
<span style={{ fontSize: "12px" }}>AI</span>
</Stack>
}
/>
{ollama && (
<FormControlLabel
sx={{ float: "right" }}
control={
<Switch
checked={useAi}
onChange={() => setUseAi(!useAi)}
size="small"
/>
}
label={
<Stack
direction="row"
sx={{ justifyContent: "center", alignItems: "center" }}
>
<span style={{ fontSize: "12px" }}>AI</span>
</Stack>
}
/>
)}
<div className="settings">
<Stack
direction={windowWidth > 800 ? "row" : "column"}
Expand Down

0 comments on commit a24b903

Please sign in to comment.