Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion translate-backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def source2wakati_byLines(source):
if letter_default[num] == "ー": # 長音は長音のまま
letter[num] = letter_default[num]
kana = "".join(letter)
for num in range(min(len(letter), len(letter_normal))):
if letter[num] == "ー" and (hinshi == "動詞"):
kana = kana_normal
if (
letter_default[0] in mapping.mapping_alpha
or letter_default[0] in mapping.mapping_alpha_CAP
Expand All @@ -102,12 +105,19 @@ def source2wakati_byLines(source):
target.append(kana)
elif prehinshi_specific == "数詞" and hinshi == "名詞": # 数字と単位の間は空けない
target.append(kana)
elif hinshi == "形状詞" and kana == "ヨー": # 「そのような」は1語
target.append(kana)
elif kana == "*":
pass
elif hinshi == "補助記号":
target.append(kana)
if hinshi_specific == "括弧開":
target.append(" " + kana)
else:
target.append(kana)
elif target == []:
target.append(kana)
elif prehinshi_specific == "括弧開":
target.append(kana)
else:
target.append(" " + kana)
prehinshi = hinshi
Expand Down
6 changes: 6 additions & 0 deletions translate-backend/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
"?": "⠢",
"「": "⠤",
"」": "⠤",
"&": "⠰⠯",
"&": "⠰⠯",
"(": "⠶",
")": "⠶",
"(": "⠶",
")": "⠶",
}

mapping_alpha = {
Expand Down
3 changes: 2 additions & 1 deletion translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"setup": "npm run setup:env && npm run setup:ci",
"setup:env": "cp .env.sample .env",
"setup:ci": "npm ci",
"dev": "vite",
"dev": "vite & npm run backend:dev",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここに書くよりもrootにあるpackage.jsonに書く方が自然かも?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後、最近分かったけどこれやるとバックエンドの終了が不可能になることがあるからやめたほうがよいかも。

"backend:dev": "cd ../translate-backend && . ./env/bin/activate && uvicorn main:app --reload --port 8000 && deactivate",
"build": "vite build",
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
Expand Down
50 changes: 48 additions & 2 deletions translate/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
IconButton,
Typography,
TextField,
FormControlLabel,
Switch,
} from "@mui/material";
import MenuIcon from "@mui/icons-material/Menu";
import { useTheme } from "@mui/material/styles";
Expand All @@ -25,6 +27,10 @@ function App() {
//const [displayTargetText, setDisplayTargetText] = useState("");
const [targetText, setTargetText] = useState("");

const [isPageNumberOn, setIsPageNumberOn] = useState(false);
const [fileName, setFileName] = useState("");
const [showWarning, setShowWarning] = useState(false);

async function source2wakati(text: string) {
const response = await fetch(
`${API_ENDPOINT}/source2wakati?sourceText=` + text,
Expand Down Expand Up @@ -155,15 +161,55 @@ function App() {
Copy
</Button>
</div>
<div>
<label>
ファイル名:
<input
type="text"
value={fileName}
onChange={(name) => {
setFileName(name.target.value);
setShowWarning(false);
}} // ユーザーの入力に反応してファイル名を更新
/>
.BES
</label>
{showWarning && (
<div style={{ color: "red" }}>
ファイル名を入力してください。
</div>
)}
</div>
<div style={{ display: "flex", justifyContent: "flex-end" }}>
<FormControlLabel
control={
<Switch
checked={isPageNumberOn}
onChange={() => {
setIsPageNumberOn(!isPageNumberOn);
}}
/>
}
label="ページ番号あり"
labelPlacement="start"
/>
</div>
<div style={{ display: "flex", justifyContent: "flex-end" }}>
<Button
onClick={() => {
const buffer = unicodeToBes(targetText.replace(/\n/g, "\\n"));
const buffer = unicodeToBes(
targetText.replace(/\n/g, "\\n"),
isPageNumberOn,
);
const blob = new Blob([buffer], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
if (fileName.trim() === "") {
setShowWarning(true); // ファイル名が空の場合、警告を表示
return;
}
a.href = url;
a.download = "output.BES";
a.download = fileName + ".BES";
a.click();
}}
>
Expand Down
Loading