From 4ca096ba7138923509516cafa5f34a4ee1ed8c53 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 26 Jun 2022 11:38:45 -0700 Subject: [PATCH] move CultureInfo to QSBLocalization --- QSB/Localisation/QSBLocalization.cs | 25 +++++++++++++++++++++++++ QSB/RespawnSync/RespawnHUDMarker.cs | 3 +-- QSB/Utility/UIHelper.cs | 28 +--------------------------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/QSB/Localisation/QSBLocalization.cs b/QSB/Localisation/QSBLocalization.cs index 9b230202..a8cee54e 100644 --- a/QSB/Localisation/QSBLocalization.cs +++ b/QSB/Localisation/QSBLocalization.cs @@ -1,6 +1,7 @@ using QSB.Utility; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; @@ -52,4 +53,28 @@ public static class QSBLocalization Current = newTranslation; LanguageChanged?.Invoke(); } + + public static CultureInfo CultureInfo + => Current.Language switch + { + /* + * Language tags from BCP-47 standard, implemented by windows + * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c + * I have no fucking idea if this will work on linux. ¯\_(ツ)_/¯ + */ + + TextTranslation.Language.ENGLISH => new CultureInfo("en"), + TextTranslation.Language.SPANISH_LA => new CultureInfo("es-419"), + TextTranslation.Language.GERMAN => new CultureInfo("de"), + TextTranslation.Language.FRENCH => new CultureInfo("fr"), + TextTranslation.Language.ITALIAN => new CultureInfo("it"), + TextTranslation.Language.POLISH => new CultureInfo("pl"), + TextTranslation.Language.PORTUGUESE_BR => new CultureInfo("pt-BR"), + TextTranslation.Language.JAPANESE => new CultureInfo("ja"), + TextTranslation.Language.RUSSIAN => new CultureInfo("ru"), + TextTranslation.Language.CHINESE_SIMPLE => new CultureInfo("zh-Hans"), + TextTranslation.Language.KOREAN => new CultureInfo("ko"), + TextTranslation.Language.TURKISH => new CultureInfo("tr"), + _ => new CultureInfo("en") // what + }; } diff --git a/QSB/RespawnSync/RespawnHUDMarker.cs b/QSB/RespawnSync/RespawnHUDMarker.cs index 72eaa5a2..8d5b0c22 100644 --- a/QSB/RespawnSync/RespawnHUDMarker.cs +++ b/QSB/RespawnSync/RespawnHUDMarker.cs @@ -1,6 +1,5 @@ using QSB.Localisation; using QSB.ShipSync; -using QSB.Utility; using UnityEngine; namespace QSB.RespawnSync; @@ -13,7 +12,7 @@ public class RespawnHUDMarker : HUDDistanceMarker { _markerRadius = 0.2f; _markerTarget = transform; - _markerLabel = QSBLocalization.Current.RespawnPlayer.ToUpper(UIHelper.GetCurrentCultureInfo()); + _markerLabel = QSBLocalization.Current.RespawnPlayer.ToUpper(QSBLocalization.CultureInfo); _isReady = true; base.InitCanvasMarker(); diff --git a/QSB/Utility/UIHelper.cs b/QSB/Utility/UIHelper.cs index ef15b672..e8fc1fe3 100644 --- a/QSB/Utility/UIHelper.cs +++ b/QSB/Utility/UIHelper.cs @@ -1,6 +1,4 @@ -using QSB.Localisation; -using System.Globalization; -using System.Linq; +using System.Linq; namespace QSB.Utility; @@ -21,28 +19,4 @@ internal static class UIHelper DebugLog.DebugWrite($"Added text \"{text}\" to the UI table with index {key}"); return (UITextType)key; } - - public static CultureInfo GetCurrentCultureInfo() - => QSBLocalization.Current.Language switch - { - /* - * Language tags from BCP-47 standard, implemented by windows - * https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c - * I have no fucking idea if this will work on linux. ¯\_(ツ)_/¯ - */ - - TextTranslation.Language.ENGLISH => new CultureInfo("en"), - TextTranslation.Language.SPANISH_LA => new CultureInfo("es-419"), - TextTranslation.Language.GERMAN => new CultureInfo("de"), - TextTranslation.Language.FRENCH => new CultureInfo("fr"), - TextTranslation.Language.ITALIAN => new CultureInfo("it"), - TextTranslation.Language.POLISH => new CultureInfo("pl"), - TextTranslation.Language.PORTUGUESE_BR => new CultureInfo("pt-BR"), - TextTranslation.Language.JAPANESE => new CultureInfo("ja"), - TextTranslation.Language.RUSSIAN => new CultureInfo("ru"), - TextTranslation.Language.CHINESE_SIMPLE => new CultureInfo("zh-Hans"), - TextTranslation.Language.KOREAN => new CultureInfo("ko"), - TextTranslation.Language.TURKISH => new CultureInfo("tr"), - _ => new CultureInfo("en") // what - }; } \ No newline at end of file