lightweight variant (#1)

Reviewed-on: #1
Co-authored-by: Aleksandr Neychev <alexnejchev73@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
2026-08-12 13:37:30 +00:00
committed by alex
parent a0d3098fe4
commit 55ac8e6556
147 changed files with 4055 additions and 2349 deletions
+41
View File
@@ -0,0 +1,41 @@
using System.Globalization;
namespace CursorLang.Core.Models;
/// <summary>
/// A keyboard layout in a form convenient for display.
/// </summary>
/// <param name="LocaleId">The locale identifier (the low word of HKL).</param>
/// <param name="ShortName">A short name for the popup at the cursor, "RU" for instance.</param>
/// <param name="DisplayName">The full name, "RU — русский (Россия)" for instance.</param>
public sealed record KeyboardLayout(int LocaleId, string ShortName, string DisplayName)
{
/// <summary>
/// Builds the model from a locale identifier. Unknown locales are not an
/// error: for them we show the identifier itself.
/// </summary>
public static KeyboardLayout FromLocaleId(int localeId)
{
CultureInfo? culture = TryGetCulture(localeId);
if (culture is null)
{
string fallback = $"0x{localeId:X4}";
return new KeyboardLayout(localeId, fallback, fallback);
}
string shortName = culture.TwoLetterISOLanguageName.ToUpperInvariant();
return new KeyboardLayout(localeId, shortName, $"{shortName} — {culture.NativeName}");
}
private static CultureInfo? TryGetCulture(int localeId)
{
try
{
return new CultureInfo(localeId);
}
catch (CultureNotFoundException)
{
return null;
}
}
}