mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
* Localization capability for each language, import & export * Lines with stat names (IVs/EVs) can be configured to many representations (X/X/X/X/X/X, HABCDS, etc). * Add nonstandard localizations * Add token types for Showdown's new set format * Add new program settings for hover & export styles. Allows users to select which presentation format they want for the hover previews, as well as the set export format. * Revises preview hover GUI to use new settings * Revises export events to use new settings * Moves no longer indicate end of set * Enhance robustness of stat parsing * Expand all settings in settings editor on form load * Extract clipboard -> sets operation to api for maintainability & reusability
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Language code & string asset loading.
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Gets the language from the requested language code.
|
|
/// </summary>
|
|
/// <param name="lang">Language code</param>
|
|
/// <returns>Index of the language code; if not a valid language code, returns the <see cref="DefaultLanguageIndex"/>.</returns>
|
|
public static int GetLanguageIndex(string lang)
|
|
{
|
|
int l = Array.IndexOf(LanguageCodes, lang);
|
|
return l < 0 ? DefaultLanguageIndex : l;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether the language code is supported.
|
|
/// </summary>
|
|
/// <param name="lang">Language code</param>
|
|
/// <returns>True if valid, False otherwise</returns>
|
|
public static bool IsLanguageValid(string lang) => Array.IndexOf(LanguageCodes, lang) != -1;
|
|
|
|
/// <summary>
|
|
/// Language codes supported for loading string resources
|
|
/// </summary>
|
|
/// <see cref="ProgramLanguage"/>
|
|
public static ReadOnlySpan<string> AllSupportedLanguages => LanguageCodes;
|
|
|
|
private static readonly string[] LanguageCodes = ["ja", "en", "fr", "it", "de", "es", "ko", "zh-Hans", "zh-Hant"];
|
|
|
|
/// <summary>
|
|
/// Pokétransporter location names, ordered per index of <see cref="LanguageCodes"/>
|
|
/// </summary>
|
|
private static readonly string[] ptransp = ["ポケシフター", "Poké Transfer", "Poké Fret", "Pokétrasporto", "Poképorter", "Pokétransfer", "포케시프터", "宝可传送", "寶可傳送"];
|
|
|
|
/// <summary>
|
|
/// Gets the Met Location display name for the Pokétransporter.
|
|
/// </summary>
|
|
/// <param name="language">Language Index from <see cref="LanguageCodes"/></param>
|
|
public static string GetTransporterName(int language)
|
|
{
|
|
if ((uint)language >= ptransp.Length)
|
|
language = 2;
|
|
return ptransp[language];
|
|
}
|
|
|
|
/// <inheritdoc cref="GetTransporterName(int)"/>
|
|
/// <param name="lang">Language name from <see cref="LanguageCodes"/></param>
|
|
public static string GetTransporterName(string lang) => GetTransporterName(GetLanguageIndex(lang));
|
|
|
|
/// <summary>
|
|
/// Gets a list of strings for the specified language and file type.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|