generated from karashiiro/DalamudPluginProjectTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Glossian.cs
66 lines (58 loc) · 2.51 KB
/
Glossian.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// <copyright file="Glossian.cs" company="lokinmodar">
// Copyright (c) lokinmodar. All rights reserved.
// Licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License license.
// </copyright>
using System;
using System.Linq;
using System.Threading.Tasks;
using Echoglossian.Properties;
using NTextCat;
using Humanizer;
namespace Echoglossian
{
public partial class Echoglossian
{
private static readonly RankedLanguageIdentifierFactory Factory = new();
private static RankedLanguageIdentifier identifier;
/// <summary>
/// Detects which language the source text is in.
/// </summary>
/// <param name="message">text to have the source language identified.</param>
/// <returns>Returns the detected language code.</returns>
private static string LangIdentify(string message)
{
// Sanitizer sanitizer = new(ClientLanguage);
string sanitizedString = sanitizer.Sanitize(message);
#if DEBUG
PluginLog.Debug($"Message in Lang Method: {sanitizedString}");
#endif
Tuple<NTextCat.LanguageInfo, double> mostCertainLanguage = identifier.Identify(sanitizedString).FirstOrDefault();
#if DEBUG
PluginLog.Debug($"Most Certain language: {mostCertainLanguage?.Item1.Iso639_2T}");
#endif
return mostCertainLanguage != null
? mostCertainLanguage.Item1.Iso639_2T
: Resources.LangIdentError;
}
/// <summary>
/// Translates the sentences passed to it using the selected engine.
/// </summary>
/// <param name="text">Text to be translated.</param>
/// <returns>Returns the translated text passed in the call parameter.</returns>
/// <exception cref="Exception">Returns exception in case something goes wrong in the translation steps.</exception>
private string Translate(string text)
{
return this.translationService.Translate(text, ClientStateInterface.ClientLanguage.Humanize(), langDict[languageInt].Code);
}
/// <summary>
/// Translates the sentences passed to it using the selected engine.
/// </summary>
/// <param name="text">Text to be translated.</param>
/// <returns>Returns the translated text passed in the call parameter.</returns>
/// <exception cref="Exception">Returns exception in case something goes wrong in the translation steps.</exception>
private Task<string> TranslateAsync(string text)
{
return this.translationService.TranslateAsync(text, ClientStateInterface.ClientLanguage.Humanize(), langDict[languageInt].Code);
}
}
}