forked from Shinonome/dots-hyprland
Fix translator output parsing using trans brief mode
This commit is contained in:
@@ -63,10 +63,10 @@ Item {
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: translateProc
|
id: translateProc
|
||||||
command: ["bash", "-c", `trans -no-theme -no-bidi`
|
command: ["bash", "-c", `trans -brief`
|
||||||
+ ` -source '${StringUtils.shellSingleQuoteEscape(root.sourceLanguage)}'`
|
+ ` -source '${StringUtils.shellSingleQuoteEscape(root.sourceLanguage)}'`
|
||||||
+ ` -target '${StringUtils.shellSingleQuoteEscape(root.targetLanguage)}'`
|
+ ` -target '${StringUtils.shellSingleQuoteEscape(root.targetLanguage)}'`
|
||||||
+ ` -no-ansi '${StringUtils.shellSingleQuoteEscape(root.inputField.text.trim())}'`]
|
+ ` '${StringUtils.shellSingleQuoteEscape(root.inputField.text.trim())}'`]
|
||||||
property string buffer: ""
|
property string buffer: ""
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
@@ -74,13 +74,8 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
// 1. Split into sections by double newlines
|
// With -brief mode, we get output with no metadata
|
||||||
const sections = translateProc.buffer.trim().split(/\n\s*\n/);
|
root.translatedText = translateProc.buffer.trim();
|
||||||
// console.log("BUFFER:", translateProc.buffer);
|
|
||||||
// console.log("SECTIONS:", sections);
|
|
||||||
|
|
||||||
// 2. Extract relevant data
|
|
||||||
root.translatedText = sections.length > 1 ? sections[1].trim() : "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user