Docs · API reference · Verso.Localization

VersoCultures Class#

The languages Verso ships an interface in, and the rules for picking one.

public static class VersoCultures

Inheritance System.Object → VersoCultures

Remarks#

Every host answers the same question differently: the CLI has a --language option, the web server has an Accept-Language header, the editor extension has a setting. They all end up here so that the answer is the same wherever it was asked, and so that adding a language is one entry rather than a search through four projects.

Fields#

Default Field#

The language used when nothing else resolves, and the one every string is written in.

public const string Default = "en";

Field Value#

System.String

EnvironmentVariable Field#

Environment variable read when no language was requested explicitly. It exists for containers and CI, where passing an option to every invocation is awkward.

public const string EnvironmentVariable = "VERSO_LANGUAGE";

Field Value#

System.String

Option Field#

The command-line option every host accepts to name a language.

public const string Option = "--language";

Field Value#

System.String

Pseudo Field#

A generated stand-in for a real translation. Every string is accented and bracketed, so running the interface in it makes anything still in plain English obvious at a glance, and the padding shows where a longer translation would be clipped. It is deliberately absent from Supported so it never appears in a language picker; ask for it by name.

public const string Pseudo = "qps-Ploc";

Field Value#

System.String

Properties#

Supported Property#

The languages offered in the interface, in the order a picker should list them.

public static System.Collections.Generic.IReadOnlyList<string> Supported { get; }

Property Value#

System.Collections.Generic.IReadOnlyList<System.String>

Methods#

ApplyUiCulture(CultureInfo) Method#

Applies a language to the interface without touching how numbers and dates are formatted.

public static void ApplyUiCulture(System.Globalization.CultureInfo culture);

Parameters#

culture System.Globalization.CultureInfo

The language to display the interface in.

Remarks#

The two are deliberately separate. A notebook's own results are data, and this process runs the kernels that produce them, so moving the formatting culture would change a cell's output because somebody picked a menu language. Hosts that run kernels elsewhere, such as the editor extension, can afford to move both and do.

FromArguments(IReadOnlyList<string>) Method#

Reads the language named by Option out of raw process arguments.

public static string? FromArguments(System.Collections.Generic.IReadOnlyList<string> args);

Parameters#

args System.Collections.Generic.IReadOnlyList<System.String>

The process arguments.

Returns#

System.String
The requested language tag, or null when the option is absent.

Remarks#

A scan rather than a parse, because the callers that need this need it before parsing is possible: command help is written while the command tree is built, and the notebook host has no parser at all. Both --language de and --language=de are accepted, and anything else is left alone for a real parser to report in the ordinary way.

Resolve(string) Method#

Resolves the language to use from an explicit request, falling back through the environment variable and the operating system to English.

public static System.Globalization.CultureInfo Resolve(string? requested);

Parameters#

requested System.String

A language tag from a command-line option or a setting, or null when none was given. The literal string auto is treated the same as null, because that is what the editor setting stores for "decide for me".

Returns#

System.Globalization.CultureInfo
A culture that has translations, or the invariant-language English culture.

TryMatch(string, CultureInfo) Method#

Matches a language tag against the shipped set, narrowing a regional tag to its language where there is no regional translation.

public static bool TryMatch(string? tag, out System.Globalization.CultureInfo culture);

Parameters#

tag System.String

A language tag, or null.

culture System.Globalization.CultureInfo

The matched culture, or null when there is no match.

Returns#

System.Boolean
true when the tag maps onto a shipped language.

Remarks#

de-AT resolves to de, and zh-CN reaches zh-Hans through its parent chain, which is why this walks parents rather than comparing prefixes: the tag for simplified Chinese shares no prefix with the tag a browser is likely to send.