Add `MultiMessageContext` init using global CultureInfo
This commit is contained in:
parent
169e798e8c
commit
6f1fced939
|
@ -23,6 +23,12 @@ namespace BizHawk.Client.DiscoHawk
|
|||
|
||||
public readonly struct MultiMessageContext
|
||||
{
|
||||
public static MultiMessageContext ForCurrentCulture()
|
||||
{
|
||||
MultiMessageContext mmc = new(CultureInfo.CurrentUICulture.IetfLanguageTag);
|
||||
return mmc.Culture is null ? new("en") : mmc;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<MessageContext> ReadEmbeddedAndConcat(string lang, MessageContext[] overlays)
|
||||
{
|
||||
MessageContext mc = new(lang, new() { UseIsolating = false });
|
||||
|
@ -44,12 +50,28 @@ namespace BizHawk.Client.DiscoHawk
|
|||
|
||||
private readonly IReadOnlyList<MessageContext> _contexts;
|
||||
|
||||
public readonly CultureInfo Culture;
|
||||
public readonly CultureInfo? Culture;
|
||||
|
||||
public MultiMessageContext(IReadOnlyList<MessageContext> contexts)
|
||||
{
|
||||
_contexts = contexts;
|
||||
Culture = new(_contexts.FirstOrDefault()?.Locales?.First());
|
||||
var langcode = _contexts.FirstOrDefault()?.Locales?.First();
|
||||
if (langcode is null) return;
|
||||
try
|
||||
{
|
||||
Culture = new(langcode);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
Culture = new(langcode.SubstringBefore('-'));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MultiMessageContext(string lang, params MessageContext[] overlays)
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace BizHawk.Client.DiscoHawk
|
|||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
MultiMessageContext i18n = new("en");
|
||||
var i18n = MultiMessageContext.ForCurrentCulture();
|
||||
using MainDiscoForm dialog = new(i18n);
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ namespace BizHawk.Client.DiscoHawk
|
|||
args,
|
||||
results => // invoked 0..1 times
|
||||
{
|
||||
MultiMessageContext i18n = new("en");
|
||||
var i18n = MultiMessageContext.ForCurrentCulture();
|
||||
using ComparisonResults cr = new(i18n) { textBox1 = { Text = results } };
|
||||
cr.ShowDialog();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue