DesktopLanguages class

Namespace Runic.Platform in Runic.Platform 0.23.0

public static class DesktopLanguages

The languages the user prefers, as the operating system lists them, for choosing the application's locale.

Remarks

Negotiate the list against the languages the application ships and set the result as its locale, unless the user chose one in its settings:

var locale = settings.Language ?? AppCatalog.ResolveLocale(DesktopLanguages.Preferred);
await services.GetRequiredService<IRunicApplicationLocale>().SetLocaleAsync(locale);

It needs no window or host and works in command-line tools too.

Properties

Preferred

public static IReadOnlyList<string> Preferred { get; }

The user's preferred languages as BCP 47 tags, such as de-CH or zh-Hans-CN, most preferred first, each once. Each read asks the operating system again.

Remarks

  • Windows: the user's display languages (GetUserPreferredUILanguages).
  • macOS: the user's preferred languages (CFLocaleCopyPreferredLanguages, as NSLocale.preferredLanguages).
  • Linux and other systems: the list gettext reads, LANGUAGE then LC_ALL, LC_MESSAGES and LANG, converted from POSIX locales such as de_CH.UTF-8; LANGUAGE counts only when the messages locale is not C or POSIX, as gettext does.

When the system lists none, the list holds CultureInfo.CurrentUICulture's name, and is empty for the invariant culture.