Added additional voice work update logic.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.Languages;
|
||||
|
||||
public interface ILanguageIdentifier
|
||||
{
|
||||
Language GetLanguage(string text);
|
||||
}
|
||||
56094
JSMR.Infrastructure/Common/Languages/Language.xml
Normal file
56094
JSMR.Infrastructure/Common/Languages/Language.xml
Normal file
File diff suppressed because it is too large
Load Diff
44
JSMR.Infrastructure/Common/Languages/LanguageIdentifier.cs
Normal file
44
JSMR.Infrastructure/Common/Languages/LanguageIdentifier.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using JSMR.Application.Common;
|
||||
using NTextCat;
|
||||
using System.Reflection;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.Languages;
|
||||
|
||||
public class LanguageIdentifier : ILanguageIdentifier
|
||||
{
|
||||
private readonly string[] _languages =
|
||||
[
|
||||
"eng",
|
||||
"jpn",
|
||||
"kor",
|
||||
"zho"
|
||||
];
|
||||
|
||||
private readonly RankedLanguageIdentifier _identifier;
|
||||
|
||||
public LanguageIdentifier()
|
||||
{
|
||||
RankedLanguageIdentifierFactory factory = new();
|
||||
|
||||
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("JSMR.Infrastructure.Languages.Language.xml");
|
||||
_identifier = factory.Load(stream);
|
||||
}
|
||||
|
||||
public Language GetLanguage(string text)
|
||||
{
|
||||
var rankedLanguages = _identifier.Identify(text).Where(x => _languages.Contains(x.Item1.Iso639_3));
|
||||
var identifiedLanguage = rankedLanguages.OrderBy(x => x.Item2).FirstOrDefault();
|
||||
|
||||
if (identifiedLanguage == null)
|
||||
return Language.Unknown;
|
||||
|
||||
return identifiedLanguage.Item1.Iso639_3 switch
|
||||
{
|
||||
"jpn" => Language.Japanese,
|
||||
"eng" => Language.English,
|
||||
"kor" => Language.Korean,
|
||||
"zho" => Language.ChineseTraditional,// Or ChineseSimplified?
|
||||
_ => Language.Unknown,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class AlingualLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.Unknown;
|
||||
public string Code => "NM";
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class ChineseLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.ChineseTraditional; // ???
|
||||
public string Code => "CHI";
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class DLSiteOfficialTranslationLanguage : ISupportedLanguage
|
||||
{
|
||||
public string Code => "DOT";
|
||||
public Language Language => Language.Unknown;
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class EnglishLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.English;
|
||||
public string Code => "ENG";
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public interface ISupportedLanguage
|
||||
{
|
||||
string Code { get; }
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class JapaneseLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.Japanese;
|
||||
public string Code => "JPN";
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class KoreanLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.Korean;
|
||||
public string Code => "KO_KR";
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class SimplifiedChineseLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.ChineseSimplified;
|
||||
public string Code => "CHI_HANS";
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
using JSMR.Application.Common;
|
||||
|
||||
namespace JSMR.Infrastructure.Common.SupportedLanguages;
|
||||
|
||||
public class TraditionalChineseLanguage : ISupportedLanguage
|
||||
{
|
||||
public Language Language => Language.ChineseTraditional;
|
||||
public string Code => "CHI_HANT";
|
||||
}
|
||||
6
JSMR.Infrastructure/Common/Time/Clock.cs
Normal file
6
JSMR.Infrastructure/Common/Time/Clock.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace JSMR.Infrastructure.Common.Time;
|
||||
|
||||
public class Clock : IClock
|
||||
{
|
||||
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
|
||||
}
|
||||
6
JSMR.Infrastructure/Common/Time/IClock.cs
Normal file
6
JSMR.Infrastructure/Common/Time/IClock.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace JSMR.Infrastructure.Common.Time;
|
||||
|
||||
public interface IClock
|
||||
{
|
||||
DateTimeOffset UtcNow { get; }
|
||||
}
|
||||
69
JSMR.Infrastructure/Common/Time/TimeProvider.cs
Normal file
69
JSMR.Infrastructure/Common/Time/TimeProvider.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
namespace JSMR.Infrastructure.Common.Time;
|
||||
|
||||
public interface ITimeProvider
|
||||
{
|
||||
DateTimeOffset Now();
|
||||
DateTimeOffset Local(int year, int month, int day, int hour);
|
||||
DateTimeOffset Local(DateTimeOffset offset);
|
||||
}
|
||||
|
||||
public abstract class TimeProvider : ITimeProvider
|
||||
{
|
||||
protected abstract string Id { get; }
|
||||
protected abstract string[] TimeZoneIds { get; }
|
||||
|
||||
private readonly IClock _clock;
|
||||
private readonly TimeZoneInfo _timeZone;
|
||||
|
||||
public TimeProvider(IClock clock)
|
||||
{
|
||||
_clock = clock;
|
||||
_timeZone = ResolveTimeZone();
|
||||
}
|
||||
|
||||
private TimeZoneInfo ResolveTimeZone()
|
||||
{
|
||||
foreach (string timeZoneId in TimeZoneIds)
|
||||
{
|
||||
if (TimeZoneInfo.TryFindSystemTimeZoneById(timeZoneId, out TimeZoneInfo? timeZoneInfo))
|
||||
return timeZoneInfo;
|
||||
}
|
||||
|
||||
throw new TimeZoneNotFoundException($"Unable to resolve time zone for: {Id} ({string.Join(" / ", TimeZoneIds)})");
|
||||
}
|
||||
|
||||
public DateTimeOffset Now() => TimeZoneInfo.ConvertTime(_clock.UtcNow, _timeZone);
|
||||
public DateTimeOffset Local(DateTimeOffset offset) => TimeZoneInfo.ConvertTime(offset, _timeZone);
|
||||
|
||||
public DateTimeOffset Local(int year, int month, int day, int hour)
|
||||
{
|
||||
DateTime local = new(year, month, day, hour, 0, 0, DateTimeKind.Unspecified);
|
||||
TimeSpan offset = _timeZone.GetUtcOffset(local);
|
||||
|
||||
return new DateTimeOffset(local, offset);
|
||||
}
|
||||
|
||||
public DateTimeOffset CurrentScanAnchor()
|
||||
{
|
||||
DateTimeOffset now = Now();
|
||||
DateTimeOffset midnight = Local(now.Year, now.Month, now.Day, 0);
|
||||
DateTimeOffset fourPm = Local(now.Year, now.Month, now.Day, 16);
|
||||
|
||||
return now >= fourPm ? fourPm : midnight;
|
||||
}
|
||||
|
||||
public DateTimeOffset PreviousScanAnchor(DateTimeOffset scanAnchorTokyo)
|
||||
{
|
||||
// Normalize to Tokyo (no-op if already)
|
||||
var a = TimeZoneInfo.ConvertTime(scanAnchorTokyo, _timeZone);
|
||||
return a.Hour == 16
|
||||
? Local(a.Year, a.Month, a.Day, 0)
|
||||
: Local(a.AddDays(-1).Year, a.AddDays(-1).Month, a.AddDays(-1).Day, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public class TokyoTimeProvider(IClock clock) : TimeProvider(clock)
|
||||
{
|
||||
protected override string Id => "Tokyo Standard Time";
|
||||
protected override string[] TimeZoneIds => ["Tokyo Standard Time", "Asia/Tokyo"];
|
||||
}
|
||||
Reference in New Issue
Block a user