Update API reference and use system language

Steam isn't used anymore
This commit is contained in:
Norbi Peti 2021-05-02 02:58:24 +02:00
parent ae8fd9f7d5
commit 1ef1625b92
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 21 additions and 23 deletions

View file

@ -36,20 +36,17 @@
<HintPath>..\packages\Lib.Harmony.2.0.2\lib\net48\0Harmony.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="GamecraftModdingAPI, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\GamecraftModdingAPI.dll</HintPath>
<Reference Include="TechbloxModdingAPI">
<HintPath>..\..\GamecraftModdingAPI\TechbloxModdingAPI\bin\Debug\net472\TechbloxModdingAPI.dll</HintPath>
</Reference>
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\IllusionPlugin.dll</HintPath>
<Reference Include="IllusionPlugin">
<HintPath>..\..\GamecraftModdingAPI\TechbloxModdingAPI\bin\Debug\net472\IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\..\ref\Gamecraft_Data\Managed\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\ref\Gamecraft_Data\Managed\RobocraftX.Common.dll</HintPath>
</Reference>
<Reference Include="Facepunch.Steamworks.Win64">
<HintPath>..\..\ref\Gamecraft_Data\Managed\Facepunch.Steamworks.Win64.dll</HintPath>
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\RobocraftX.Common.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />

View file

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using GamecraftModdingAPI;
using GamecraftModdingAPI.App;
using GamecraftModdingAPI.Commands;
using GamecraftModdingAPI.Utility;
using TechbloxModdingAPI;
using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Commands;
using TechbloxModdingAPI.Utility;
using HarmonyLib;
using IllusionPlugin;
using Newtonsoft.Json;
@ -84,7 +85,7 @@ namespace Localization
}
if ((bool) settings["autoload"])
Client.EnterMenu += TryLoadSteamLanguageMenuEnterEvent;
Client.EnterMenu += TryLoadSystemLanguageMenuEnterEvent;
}
public override void OnApplicationQuit()
@ -151,38 +152,38 @@ namespace Localization
.GetValue(null);
}
private void TryLoadSteamLanguageMenuEnterEvent(object sender, MenuEventArgs args)
private void TryLoadSystemLanguageMenuEnterEvent(object sender, MenuEventArgs args)
{
TryLoadSteamLanguage();
Client.EnterMenu -= TryLoadSteamLanguageMenuEnterEvent;
TryLoadSystemLanguage();
Client.EnterMenu -= TryLoadSystemLanguageMenuEnterEvent;
}
private void TryLoadSteamLanguage()
private void TryLoadSystemLanguage()
{
string lang = Steamworks.SteamUtils.SteamUILanguage;
string lang = CultureInfo.InstalledUICulture.EnglishName.Split(' ')[0].ToLower();
string first2 = lang.Substring(0, 2);
// try some possibly valid language codes
if (File.Exists(Path.Combine(_pluginFolder.FullName, lang + ".json")))
{
Logging.MetaLog($"Automatically detected Steam UI language {lang}, loading translations...");
Logging.MetaLog($"Automatically detected system UI language {lang}, loading translations...");
LoadTranslation(lang);
}
else if (File.Exists(Path.Combine(_pluginFolder.FullName, first2 + ".json")))
{
lang = first2;
Logging.MetaLog($"Automatically detected Steam UI language {lang}, loading translations...");
Logging.MetaLog($"Automatically detected system UI language {lang}, loading translations...");
LoadTranslation(lang);
}
else if (File.Exists(Path.Combine(_pluginFolder.FullName, first2 + "-" + first2 + ".json")))
{
// a lot of standard languages codes are like fr-fr (French from France), but this won't work for English (nor fr-CA French from Canada)
lang = first2 + "-" + first2;
Logging.MetaLog($"Automatically detected Steam UI language {lang}, loading translations...");
Logging.MetaLog($"Automatically detected system UI language {lang}, loading translations...");
LoadTranslation(lang);
}
else
{
Logging.MetaLog($"Translations for Steam UI language {lang} are not available, skipping...");
Logging.MetaLog($"Translations for system UI language {lang} are not available, skipping...");
}
}