Table of Contents

Class TranslationUnit

Namespace
Tlumach.Avalonia
Assembly
Tlumach.Avalonia.dll

Represents a unit of translation - a unit of text (a word, a phrase, a sentence, etc.) in a translation accessible using a unique key.

This class is used in the code generated for Avalonia applications. It exposes the text as an observable (Value) that Avalonia bindings subscribe to.

public class TranslationUnit : BaseTranslationUnit, IDisposable
Inheritance
TranslationUnit
Implements
Derived
Inherited Members

Constructors

TranslationUnit(string, TranslationManager, TranslationConfiguration, bool)

Initializes a new instance of the TranslationUnit class.

For internal use. This constructor is used by UntranslatedUnit.

protected TranslationUnit(string sourceValue, TranslationManager translationManager, TranslationConfiguration translationConfiguration, bool containsPlaceholders)

Parameters

sourceValue string

The initial value of the text.

translationManager TranslationManager

The translation manager to which the unit is bound.

translationConfiguration TranslationConfiguration

The translation configuration used to create the unit.

containsPlaceholders bool

An indicator of whether the unit contains placeholders.

TranslationUnit(TranslationManager, TranslationConfiguration, string, bool)

Initializes a new instance of the TranslationUnit class.

For internal use. This constructor is used by the code generated by Generator.

public TranslationUnit(TranslationManager translationManager, TranslationConfiguration translationConfiguration, string key, bool containsPlaceholders)

Parameters

translationManager TranslationManager

The translation manager to which the unit is bound.

translationConfiguration TranslationConfiguration

The translation configuration used to create the unit.

key string

The key of the unit.

containsPlaceholders bool

An indicator of whether the unit contains placeholders.

Properties

CurrentValue

Gets the current text of the unit, i.e., the text that Value has sent last.

public string CurrentValue { get; }

Property Value

string

Value

Gets an observable that sends the current text of the unit to each new subscriber and the new text to all subscribers every time the culture of the associated translation manager changes or NotifyPlaceholdersUpdated() is called.

The new text may be sent on any thread; Avalonia bindings post it to the UI thread themselves.

public IObservable<string> Value { get; }

Property Value

IObservable<string>

Methods

Dispose()

Unsubscribes the unit from the culture changes of the translation manager and stops the Value observable, which then drops its subscribers and sends no more text.

public void Dispose()

Dispose(bool)

Releases the resources of the unit.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to unsubscribe the unit from the culture changes of the translation manager and stop the Value observable, which then drops its subscribers and sends no more text; false to do nothing.

NotifyPlaceholdersUpdated()

Notifies XAML bindings that they need to request a new value and update the controls.

public override void NotifyPlaceholdersUpdated()

ToString()

Returns the current text of the unit.

public override string ToString()

Returns

string

The value of CurrentValue.

Operators

implicit operator string(TranslationUnit)

Converts the unit to its current text.

public static implicit operator string(TranslationUnit unit)

Parameters

unit TranslationUnit

The unit to convert.

Returns

string

The current text of unit, or an empty string if unit is null.