Handle vanilla -lang and -language CLI flags for I18n
This commit is contained in:
parent
632df52ce7
commit
3ead63f9ac
2 changed files with 23 additions and 2 deletions
|
|
@ -21,7 +21,10 @@ global using static TShockAPI.I18n;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using GetText;
|
using GetText;
|
||||||
|
using Terraria.Initializers;
|
||||||
|
using Terraria.Localization;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -29,8 +32,7 @@ namespace TShockAPI
|
||||||
static string TranslationsDirectory => Path.Combine(AppContext.BaseDirectory, "i18n");
|
static string TranslationsDirectory => Path.Combine(AppContext.BaseDirectory, "i18n");
|
||||||
static CultureInfo TranslationCultureInfo
|
static CultureInfo TranslationCultureInfo
|
||||||
{
|
{
|
||||||
get
|
get {
|
||||||
{
|
|
||||||
// cross-platform mapping of cultureinfos can be a bit screwy, so give our users
|
// cross-platform mapping of cultureinfos can be a bit screwy, so give our users
|
||||||
// the chance to explicitly spell out which translation they would like to use.
|
// the chance to explicitly spell out which translation they would like to use.
|
||||||
// this is an environment variable instead of a flag because this needs to be
|
// this is an environment variable instead of a flag because this needs to be
|
||||||
|
|
@ -39,6 +41,24 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
return new CultureInfo(overrideLang);
|
return new CultureInfo(overrideLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CultureInfo Redirect(CultureInfo cultureInfo)
|
||||||
|
=> cultureInfo.Name == "zh-Hans" ? new CultureInfo("zh-CN") : cultureInfo;
|
||||||
|
|
||||||
|
if (Terraria.Program.LaunchParameters.TryGetValue("-lang", out var langArg)
|
||||||
|
&& int.TryParse(langArg, out var langId)) {
|
||||||
|
if (GameCulture._legacyCultures.TryGetValue(langId, out var culture)) {
|
||||||
|
return Redirect(culture.CultureInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Terraria.Program.LaunchParameters.TryGetValue("-language", out var languageArg)) {
|
||||||
|
var culture = GameCulture._legacyCultures.Values.SingleOrDefault(c => c.Name == languageArg);
|
||||||
|
if (culture != null) {
|
||||||
|
return Redirect(culture.CultureInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CultureInfo.CurrentUICulture;
|
return CultureInfo.CurrentUICulture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ Use past tense when adding new entries; sign your name off when you add or chang
|
||||||
* Check loadout slots for hacked item stacks. (@drunderscore)
|
* Check loadout slots for hacked item stacks. (@drunderscore)
|
||||||
* Fix players being kicked after using the Flamethrower to apply the `OnFire3` debuff for `1200` ticks. (@BashGuy10)
|
* Fix players being kicked after using the Flamethrower to apply the `OnFire3` debuff for `1200` ticks. (@BashGuy10)
|
||||||
* Fix being kicked for using the new sponge types on liquid. (@BashGuy10)
|
* Fix being kicked for using the new sponge types on liquid. (@BashGuy10)
|
||||||
|
* Added support of `-lang` and `-language` flags for our i18n system. (@KawaiiYuyu)
|
||||||
|
|
||||||
## TShock 4.5.18
|
## TShock 4.5.18
|
||||||
* Fixed `TSPlayer.GiveItem` not working if the player is in lava. (@PotatoCider)
|
* Fixed `TSPlayer.GiveItem` not working if the player is in lava. (@PotatoCider)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue