RunicViewsTranslations class

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

public static class RunicViewsTranslations

Runic's own text from the runic-views catalog (English and German): validation messages of the built-in DataAnnotations attributes, and the DesktopPlatformTexts that Runic shows in native UI. The page's field errors come from the same catalog in the @runic-artifex/views-translations npm package.

Remarks

services.AddRunicViewsTranslations() wires everything for an application that registers its Translations context with Runic.Translations.Hosting. Without dependency injection, add RunicViewsTranslations.CatalogRegistration to the application's TranslationContext builder, set RunicViewsTranslations.ValidationText as RunicValidationOptions.TextFor, and call RunicViewsTranslations.FollowPlatformTexts.

An application changes single messages, or adds a locale, in its own runic.json ("overrides" of the runic-views catalog from this package); the text it overrides follows the same locale.

Fields

CatalogId

public const string CatalogId = "runic-views"

The catalog's ID, runic-views: the "catalog" of an override in runic.json.

Properties

CatalogRegistration

public static TranslationCatalogRegistration CatalogRegistration { get; }

The runic-views catalog, for a TranslationContext builder: TranslationContext.CreateBuilder().AddCatalog(AppTextCatalog.Registration).AddCatalog(RunicViewsTranslations.CatalogRegistration). AddRunicViewsTranslations() registers it with Runic.Translations.Hosting.

Methods

FollowPlatformTexts

public static IDisposable FollowPlatformTexts(ITranslationContext context, Action<ArgumentException>? onError = null)

Sets DesktopPlatformTexts.Current from the context now and whenever the runic-views catalog publishes new text: after a locale switch (the context follows the application's locale with IRunicApplicationLocale.Follow(context.SetLocaleAsync)) and after a refresh of its overlays.

Parameters

context

A Translations context with RunicViewsTranslations.CatalogRegistration.

onError

Receives a text the platform refused, or null.

Returns

A registration; dispose it to stop following. The current texts stay.

Exceptions

ArgumentNullException

context is null.

KeyNotFoundException

The context has no runic-views catalog.

Remarks

The texts change before IRunicApplicationLocale.LocaleChanged is raised, as the context switches first. A text that DesktopPlatformTexts refuses, such as an overridden untitled file name with a /, keeps the previous texts and is passed to onError; without it, the switch's thread sees the ArgumentException. Set the texts only through one follower: DesktopPlatformTexts.Current is process-wide.

public static RunicViewsMenuTitles MenuTitles(ITranslationContext context)

The titles of Runic Desktop's standard macOS menus in the context's current locale, with {0} for the application's name, which Runic inserts. Map them to DesktopStandardMenuTitles, whose members have the same names, and pass them to DesktopHost.SetStandardMenuTitles (the README shows how).

Parameters

context

A Translations context with RunicViewsTranslations.CatalogRegistration.

Exceptions

ArgumentNullException

context is null.

KeyNotFoundException

The context has no runic-views catalog.

Remarks

This package does not reference Runic.Desktop, so that CS-WebUI applications do not depend on it.

PlatformTexts

public static DesktopPlatformTexts PlatformTexts(ITranslationContext context)

The DesktopPlatformTexts in the context's current locale: Linux dialog titles, the untitled file name, the macOS Choose an application title, the Linux keyring label, shortcut key names, a browser window's error pages, the title of a Windows window while WebView2 starts, and a CS-WebUI window's error pages and connection banners.

Parameters

context

A Translations context with RunicViewsTranslations.CatalogRegistration.

Exceptions

ArgumentNullException

context is null.

KeyNotFoundException

The context has no runic-views catalog.

ValidationReference

public static TranslationReference? ValidationReference(ValidationAttribute attribute, RunicValidationMember member)

The runic-views reference that RunicViewsTranslations.ValidationText gives an attribute, as a Translations TranslationReference, for code that resolves it in C# (ITranslationContext.Resolve).

Exceptions

ArgumentNullException

An argument is null.

ValidationText

public static RunicTextReference? ValidationText(ValidationAttribute attribute, RunicValidationMember member)

A RunicValidationOptions.TextFor that gives the built-in DataAnnotations attributes a text reference of the runic-views catalog, which the page shows in the window's language; null for an attribute it has no text for, or one with a message of its own.

Exceptions

ArgumentNullException

An argument is null.

Remarks

It covers RequiredAttribute, MaxLengthAttribute, MinLengthAttribute, StringLengthAttribute, LengthAttribute, RangeAttribute (inclusive limits), EmailAddressAttribute, PhoneAttribute, UrlAttribute, CreditCardAttribute, RegularExpressionAttribute, CompareAttribute, FileExtensionsAttribute, Base64StringAttribute, AllowedValuesAttribute, DeniedValuesAttribute and EnumDataTypeAttribute; types derived from them keep their message, as do attributes that set ValidationAttribute.ErrorMessage or a message resource, and a RangeAttribute with an exclusive limit.

The field's name is RunicValidationMember.DisplayName, as the attribute's message writes it. To combine it with the application's own texts, call it last: TextFor = (attribute, member) => AppText(attribute, member) ?? RunicViewsTranslations.ValidationText(attribute, member). The page resolves the reference with this catalog (@runic-artifex/views-translations); a page without it shows the reference's English fallback.