Table of Contents

Class TranslationUnit

Namespace
Tlumach.WinUI
Assembly
Tlumach.WinUI.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 WinUI (and Uno Platform) applications. It implements INotifyPropertyChanged, so XAML bindings to CurrentValue update when the language changes.

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

Constructors

TranslationUnit(TranslationManager, TranslationConfiguration, bool)

Initializes a new instance of the TranslationUnit class.

For internal use. This constructor is used by UntranslatedUnit.

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

Parameters

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 text of the unit for the current culture of the associated translation manager (or, if the unit is bound to Empty, for CurrentCulture).

The text is retrieved on the first read and then updated every time the culture of the translation manager changes or NotifyPlaceholdersUpdated() is called.

public string CurrentValue { get; }

Property Value

string

Methods

Dispose()

Unsubscribes the unit from the culture changes of the translation manager.

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; 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.

Events

PropertyChanged

Fires when the value of CurrentValue changes: when the text is retrieved on the first read of CurrentValue, and when the culture of the associated translation manager changes or NotifyPlaceholdersUpdated() is called and the text becomes different.

The notifications of the changes are raised in the synchronization context of the thread that created the unit or, if there was none, of the thread that first read CurrentValue (normally, the UI thread).

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler

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.