Table of Contents

Class NaturalLanguageString

Namespace
ActivityPub.Types.Util
Assembly
ActivityPub.Types.dll

A string that can have multiple representations in different languages.

[JsonConverter(typeof(NaturalLanguageStringConverter))]
public sealed class NaturalLanguageString
Inheritance
NaturalLanguageString
Inherited Members

Fields

_languageMap

private readonly Dictionary<string, string> _languageMap

Field Value

Dictionary<string, string>

_rootNode

private readonly NaturalLanguageString.LanguageNode _rootNode

Field Value

NaturalLanguageString.LanguageNode

Properties

DefaultValue

The language-agnostic value of this string. Will be used as a fallback if the requested language is not available, or if no user preference is available.

public string? DefaultValue { get; set; }

Property Value

string

HasLanguages

true if this string contains any language-tagged values. DefaultValue is ignored.

public bool HasLanguages { get; }

Property Value

bool

this[string[]]

Gets or sets the value of a string for a given language.

public string? this[params string[] language] { get; set; }

Parameters

language string[]

Property Value

string
See Also

LanguageMap

A map of BCP47 Language-Tags that represents this object. DefaultValue is not included.

public IReadOnlyDictionary<string, string> LanguageMap { get; }

Property Value

IReadOnlyDictionary<string, string>

Methods

CreateNode(string[])

private NaturalLanguageString.LanguageNode CreateNode(string[] language)

Parameters

language string[]

Returns

NaturalLanguageString.LanguageNode

FindNode(string[], bool)

private NaturalLanguageString.LanguageNode? FindNode(string[] language, bool exactMatch = false)

Parameters

language string[]
exactMatch bool

Returns

NaturalLanguageString.LanguageNode

FromLanguageMap(IReadOnlyDictionary<string, string>)

Constructs a NaturalLanguageString from a map of BCP47 Language-Tags.

public static NaturalLanguageString FromLanguageMap(IReadOnlyDictionary<string, string> languageMap)

Parameters

languageMap IReadOnlyDictionary<string, string>

Returns

NaturalLanguageString

Get(params string[])

Gets the value of the string for a given language. If no language tags are specified, then returns the value of DefaultValue instead.

public string? Get(params string[] language)

Parameters

language string[]

Returns

string
See Also

GetExactly(params string[])

Gets the value of the string for a given language. This version will not inherit from language roots or DefaultValue.

public string? GetExactly(params string[] language)

Parameters

language string[]

Returns

string
See Also

Has(params string[])

Checks if a value exists for the target language, or one of it's base categories. This method does not consider DefaultValue.

public bool Has(params string[] language)

Parameters

language string[]

Returns

bool
See Also

HasExactly(params string[])

Checks if a value exists for the target language and all sub-tags. This version will not inherit from language roots or DefaultValue.

public bool HasExactly(params string[] language)

Parameters

language string[]

Returns

bool
See Also

Remove(params string[])

Removes the mapping for a specific language. This will not inherit from language roots or DefaultValue.

public void Remove(params string[] language)

Parameters

language string[]

Language to unmap

Set(string, params string[])

Sets the value of the string for a given language. If no language tags are specified, then sets the value of DefaultValue instead.

public void Set(string value, params string[] language)

Parameters

value string
language string[]

Remarks

The value must be provided first due to the use of params.

See Also

Operators

implicit operator NaturalLanguageString(string)

Constructs a NaturalLanguageString from a native .NET string. The provided string will be mapped to DefaultValue.

public static implicit operator NaturalLanguageString(string defaultValue)

Parameters

defaultValue string

Returns

NaturalLanguageString