using System;
using System.Diagnostics.CodeAnalysis;
namespace PKHeX.Core;
///
/// Language code & string asset loading.
///
public static class GameLanguage
{
public const string DefaultLanguage = "en"; // English
public static int DefaultLanguageIndex => Array.IndexOf(LanguageCodes, DefaultLanguage);
public static string LanguageCode(int lang) => (uint)lang >= LanguageCodes.Length ? DefaultLanguage : LanguageCodes[lang];
public static int LanguageCount => LanguageCodes.Length;
///
/// Gets the language from the requested language code.
///
/// Language code
/// Index of the language code; if not a valid language code, returns the .
public static int GetLanguageIndex(string lang)
{
int l = Array.IndexOf(LanguageCodes, lang);
return l < 0 ? DefaultLanguageIndex : l;
}
///
/// Checks whether the language code is supported.
///
/// Language code
/// True if valid, False otherwise
public static bool IsLanguageValid(string lang) => Array.IndexOf(LanguageCodes, lang) != -1;
///
/// Language codes supported for loading string resources
///
///
public static ReadOnlySpan AllSupportedLanguages => LanguageCodes;
private static readonly string[] LanguageCodes = ["ja", "en", "fr", "it", "de", "es", "ko", "zh-Hans", "zh-Hant"];
///
/// Pokétransporter location names, ordered per index of
///
private static readonly string[] ptransp = ["ポケシフター", "Poké Transfer", "Poké Fret", "Pokétrasporto", "Poképorter", "Pokétransfer", "포케시프터", "宝可传送", "寶可傳送"];
///
/// Gets the Met Location display name for the Pokétransporter.
///
/// Language Index from
public static string GetTransporterName(int language)
{
if ((uint)language >= ptransp.Length)
language = 2;
return ptransp[language];
}
///
/// Language name from
public static string GetTransporterName(string lang) => GetTransporterName(GetLanguageIndex(lang));
///
/// Gets a list of strings for the specified language and file type.
///
public static string[] GetStrings(string ident, string lang, [ConstantExpected] string type = "text")
{
string[] data = Util.GetStringList(ident, lang, type);
if (data.Length == 0)
data = Util.GetStringList(ident, DefaultLanguage, type);
return data;
}
}