using System; using static PKHeX.Core.LanguageID; namespace PKHeX.Core; /// /// Logic relating to values. /// public static class Language { private static ReadOnlySpan Languages => [ (byte)Japanese, (byte)English, (byte)French, (byte)Italian, (byte)German, (byte)Spanish, (byte)Korean, // GS (byte)ChineseS, (byte)ChineseT, ]; // check Korean for the VC case, never possible to match string outside of this case private static ReadOnlySpan Languages_GB => Languages[..7]; // [..KOR] private static ReadOnlySpan Languages_3 => Languages[..6]; // [..KOR) private const LanguageID SafeLanguage = English; /// /// Returns the available languages for the given generation. /// /// Generation to check. /// Available languages for the given generation. public static ReadOnlySpan GetAvailableGameLanguages(int generation = PKX.Generation) => generation switch { 1 => Languages_3, // No KOR 2 => Languages_GB, 3 => Languages_3, // No KOR 4 or 5 or 6 => Languages_GB, _ => Languages, }; private static bool HasLanguage(ReadOnlySpan permitted, byte language) => permitted.Contains(language); /// /// Returns the language that is safe to use for the given generation. /// /// Generation to check. /// Preferred language. /// Game version to check. /// Language that is safe to use for the given generation. public static LanguageID GetSafeLanguage(int generation, LanguageID prefer, GameVersion game = GameVersion.Any) => generation switch { 1 when game == GameVersion.BU => Japanese, 1 => HasLanguage(Languages_3, (byte)prefer) ? prefer : SafeLanguage, 2 => HasLanguage(Languages_GB, (byte)prefer) && (prefer != Korean || game == GameVersion.C) ? prefer : SafeLanguage, 3 => HasLanguage(Languages_3 , (byte)prefer) ? prefer : SafeLanguage, 4 or 5 or 6 => HasLanguage(Languages_GB, (byte)prefer) ? prefer : SafeLanguage, _ => HasLanguage(Languages, (byte)prefer) ? prefer : SafeLanguage, }; /// /// Gets the 2-character language name for the given . /// /// Language ID to get the 2-character name for. /// 2-character language name. public static string GetLanguage2CharName(this LanguageID language) => language switch { Japanese => "ja", French => "fr", Italian => "it", German => "de", Spanish => "es", Korean => "ko", ChineseS or ChineseT => "zh", _ => GameLanguage.DefaultLanguage, }; /// /// Gets the Main Series language ID from a GameCube (C/XD) language ID. /// /// GameCube (C/XD) language ID. /// Main Series language ID. /// If no conversion is possible or maps to the same value, the input is returned. public static byte GetMainLangIDfromGC(byte value) => (LanguageGC)value switch { LanguageGC.German => (byte)German, LanguageGC.French => (byte)French, LanguageGC.Italian => (byte)Italian, LanguageGC.Spanish => (byte)Spanish, LanguageGC.UNUSED_6 => (byte)UNUSED_6, _ => value, }; /// /// Gets the GameCube (C/XD) language ID from a Main Series language ID. /// /// Main Series language ID. /// GameCube (C/XD) language ID. /// If no conversion is possible or maps to the same value, the input is returned. public static byte GetGCLangIDfromMain(byte value) => (LanguageID)value switch { French => (byte)LanguageGC.French, Italian => (byte)LanguageGC.Italian, German => (byte)LanguageGC.German, UNUSED_6 => (byte)LanguageGC.UNUSED_6, Spanish => (byte)LanguageGC.Spanish, _ => value, }; }