Implement token parsing in Linux input language

Added a method to parse tokens received from the Ibus process in the LinuxInputLanguage class. The new method, ParseTokens, trims each token from white spaces. The "GetFromIbusProcess" method now includes a call to "ParseTokens".

Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-06-27 09:49:52 +01:00
parent c3fc655bbc
commit f4760f5bd0

View File

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
@ -10,12 +11,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate.InputLanguage
{
try
{
// TODO: Parse
// xkb:us::eng English (US)
// xkb:fr::fra French
// xkb:de::ger German
// xkb:es::spa Spanish
return GetFromIbusProcess();
return ParseTokens(GetFromIbusProcess());
}
catch
{
@ -28,6 +24,19 @@ namespace Nikse.SubtitleEdit.Forms.Translate.InputLanguage
}
}
private static string[] ParseTokens(string[] tokens)
{
// xkb:us::eng English (US)
// xkb:fr::fra French
// xkb:de::ger German
// xkb:es::spa Spanish
return tokens.Select(token =>
{
var whiteSpaceIndex = token.IndexOf(' ');
return whiteSpaceIndex < 0 ? token : token.Substring(whiteSpaceIndex + 1).Trim();
}).ToArray();
}
private string[] GetFromIbusProcess()
{
var process = new Process
@ -38,7 +47,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate.InputLanguage
Arguments = "-c \"ibus list-engine\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
CreateNoWindow = true,
}
};