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 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
sourceValuestringThe initial value of the text.
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 current text of the unit, i.e., the text that Value has sent last.
public string CurrentValue { get; }
Property Value
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
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
disposingbooltrue 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
unitTranslationUnitThe unit to convert.