IRunicWindowLocale interface

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public interface IRunicWindowLocale : INotifyPropertyChanged

Inherits or implements INotifyPropertyChanged.

The locale of the Window whose scope resolved this service: the language in which its pages show text references, such as ViewModel status text and validation messages (feature translation-text/1). Take it in the constructor of a ViewModel that OpenWindowAsync resolves, or of a scoped service that ViewModel uses.

Remarks

The application owns the locale: it sets it from its settings, the operating system's language or a language switch of the page, which calls a command. The window's pages follow it without a call per string, and set the locale of their Translations runtime, so the page's own messages switch too.

A Window that sets no locale of its own follows the application's IRunicApplicationLocale, and switches with it. Setting IRunicWindowLocale.Locale gives the Window its own locale; setting null makes it follow the application again. While neither sets one, the default, each page keeps its own language.

Set it in the ViewModel's constructor, before the window opens, and the first page starts in that language. The service raises INotifyPropertyChanged.PropertyChanged for IRunicWindowLocale.Locale each time the Window's locale changes: on the setting thread when it is set here or when the window's WindowContentSession.Locale is set directly, which counts as the Window's own locale; and in a turn of the Window's model context when the application's locale changes while the Window follows it. It raises it for IRunicWindowLocale.OwnLocale when the Window's own locale changes. Outside a Window's scope, as in a unit test that constructs the ViewModel, it keeps the value without pushing it anywhere.

Since 0.17, IRunicWindowLocale.Locale returns the application's locale while the Window has none of its own. Code that saves the Window's language and sets it back later saves IRunicWindowLocale.OwnLocale, so a Window that followed the application follows it again instead of keeping the language it showed.

Properties

Locale

string? Locale { get; set; }

The window's locale, a BCP 47 tag such as de or pt-BR: its own, or the application's while it sets none. null while neither sets one and each page keeps its own.

Exceptions

ArgumentException

The value is not 1 to 64 letters, digits and -, starting with a letter.

Remarks

Setting a tag gives the Window its own locale. Setting null makes it follow the application's locale again, so reading it afterwards returns the application's locale when there is one.

OwnLocale

string? OwnLocale { get; }

The Window's own locale, or null while it follows the application's (since 0.17). Save this one and set it back through IRunicWindowLocale.Locale: null follows the application again.

Remarks

The default implementation, for a test fake, returns IRunicWindowLocale.Locale.