Class TranslationUnit
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
translationManagerTranslationManagerThe translation manager to which the unit is bound.
translationConfigurationTranslationConfigurationThe translation configuration used to create the unit.
containsPlaceholdersboolAn 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
translationManagerTranslationManagerThe translation manager to which the unit is bound.
translationConfigurationTranslationConfigurationThe translation configuration used to create the unit.
keystringThe key of the unit.
containsPlaceholdersboolAn 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
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
disposingbooltrue 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
Operators
implicit operator string(TranslationUnit)
Converts the unit to its current text.
public static implicit operator string(TranslationUnit unit)
Parameters
unitTranslationUnitThe unit to convert.