Table of Contents

Class TranslationEntry

Namespace
Tlumach.Base
Assembly
Tlumach.Base.dll

Represents an entry in the translation file. An entry may have a value (some text in a specific language) or be a reference to an external file with a translation.

Instances of this class are always owned by a dictionary which keeps the keys, and that dictionary is transferred in a way that specifies the locale. For this reason, TranslationEntry does not hold a key or locale ID.

public class TranslationEntry
Inheritance
TranslationEntry
Inherited Members

Constructors

TranslationEntry()

Initializes a new instance of the TranslationEntry class.

public TranslationEntry()

TranslationEntry(string, string?, string?, string?, KeyLocation?)

Initializes a new instance of the TranslationEntry class.

public TranslationEntry(string key, string? text, string? escapedText = null, string? reference = null, KeyLocation? keyLocation = null)

Parameters

key string

The key to which the translation entry corresponds.

text string

An optional localized text of the translation entry that has been un-escaped if necessary.

escapedText string

An optional localized text of the translation entry that has not been un-escaped.

reference string

An optional reference to an external file with the text.

keyLocation KeyLocation

The location of the entry in the original file.

Properties

ChangeDate

Gets or sets the date of the last change to this entry. Used in XLIFF format.

public DateTime? ChangeDate { get; set; }

Property Value

DateTime?

ChangeReason

Gets or sets an optional reason for the last change. Used in XLIFF format.

public string? ChangeReason { get; set; }

Property Value

string

Comment

Gets or sets an optional comment of the entry.

public string? Comment { get; set; }

Property Value

string

ContainsPlaceholders

Indicates that the text is a template and contains placeholders. When it is, use the ProcessTemplatedValue(CultureInfo, TextFormat, params object?[]) method or its overloads to format the template.

public bool ContainsPlaceholders { get; set; }

Property Value

bool

Context

Gets or sets an optional description of the context.

public string? Context { get; set; }

Property Value

string

Description

Gets or sets an optional description of the entry.

public string? Description { get; set; }

Property Value

string

Empty

Gets a static instance that represents an empty entry.

public static TranslationEntry Empty { get; }

Property Value

TranslationEntry

EscapedText

Gets or sets a localized text that has not been un-escaped. This text is used when evaluating if the localized text contains templates and when processing those templates.

public string? EscapedText { get; set; }

Property Value

string

Key

Gets the original key of the entry.

public string Key { get; }

Property Value

string

KeyLocated

public KeyLocation? KeyLocated { get; }

Property Value

KeyLocation

Phase

Gets or sets an optional translation phase/state (e.g., "extraction", "translation", "review"). Used in XLIFF format.

public string? Phase { get; set; }

Property Value

string

Placeholders

Gets an optional collection of placeholder descriptions.

public List<Placeholder>? Placeholders { get; }

Property Value

List<Placeholder>

Reference

Gets or sets an optional reference to an external file with the translation value.

A reference is set by the parser when the text starts with '@' (at) and the RecognizeFileRefs property is true.

public string? Reference { get; set; }

Property Value

string

Screen

Gets or sets an optional reference to a screenshot of the entry.

public string? Screen { get; set; }

Property Value

string

SourceText

Gets or sets an optional original text that was translated.

public string? SourceText { get; set; }

Property Value

string

Target

Gets or sets an optional target of the entry.

Targets are defined in the ARB specification as attributes of HTML elements to which the content should be assigned.

public string? Target { get; set; }

Property Value

string

Text

Gets or sets a localized text. This text has been un-escaped (if needed) during loading from the translation file.

public string? Text { get; set; }

Property Value

string

Type

Gets or sets an optional type of the entry.

Describes the type of resource. Possible values are "text", "image", "css".

public string? Type { get; set; }

Property Value

string

Video

Gets or sets an optional reference to a video of the entry.

public string? Video { get; set; }

Property Value

string

Methods

AddPlaceholder(Placeholder)

public void AddPlaceholder(Placeholder placeholder)

Parameters

placeholder Placeholder

BuildFilledMethodSignature(List<(string Name, string Type)>?, TextFormat, bool, string)

Analyzes the templated text and produces a C# method signature whose parameter list matches the placeholders found in the text. Used by the Generator to emit a strongly-typed wrapper around ProcessTemplatedValue(CultureInfo, TextFormat, params object?[]).

public string BuildFilledMethodSignature(List<(string Name, string Type)>? parameters, TextFormat textProcessingMode, bool includeCultureInfo = false, string methodName = "Filled")

Parameters

parameters List<(string Name, string Type)>

An optional list of parameters obtained from the CollectPlaceholders(string, TextFormat) method. May be empty, in which case, CollectPlaceholders will be called for the entry's text.

textProcessingMode TextFormat

The text-processing mode that drives placeholder parsing.

includeCultureInfo bool
methodName string

The name of the generated method. Defaults to "Filled".

Returns

string

A C# method signature, e.g. Filled(string name, int count, DateTime when).

CollectPlaceholders(string, TextFormat)

public List<(string Name, string Type)> CollectPlaceholders(string inputText, TextFormat textProcessingMode)

Parameters

inputText string
textProcessingMode TextFormat

Returns

List<(string Name, string Type)>

CompareByHierarchicalKey(TranslationEntry?, TranslationEntry?)

Compares two TranslationEntry instances based on their hierarchical Key property. Parents come before their children, and children of the same parent are sorted alphabetically.

public static int CompareByHierarchicalKey(TranslationEntry? left, TranslationEntry? right)

Parameters

left TranslationEntry

The first TranslationEntry to compare.

right TranslationEntry

The second TranslationEntry to compare.

Returns

int

A negative number if left comes before right, zero if equal, or a positive number if left comes after right.

Lock()

For internal use only.

public void Lock()

ProcessTemplatedValue(CultureInfo, TextFormat, IDictionary<string, object?>)

Processes the templated translation entry by substituting the placeholders with actual values and returns the final text.

public string ProcessTemplatedValue(CultureInfo culture, TextFormat textProcessingMode, IDictionary<string, object?> placeholderValuesDict)

Parameters

culture CultureInfo

The culture/locale for which the text is needed.

textProcessingMode TextFormat

The required text processing mode.

placeholderValuesDict IDictionary<string, object>

The values for the placeholders of the entry.

Returns

string

The requested text or an empty string.

Exceptions

TemplateProcessingException

thrown if processing of the template fails.

ProcessTemplatedValue(CultureInfo, TextFormat, OrderedDictionary)

Processes the templated translation entry by substituting the placeholders with actual values and returns the final text.

public string ProcessTemplatedValue(CultureInfo culture, TextFormat textProcessingMode, OrderedDictionary placeholderValuesOrderedDict)

Parameters

culture CultureInfo

The culture/locale for which the text is needed.

textProcessingMode TextFormat

The required text processing mode.

placeholderValuesOrderedDict OrderedDictionary

The values for the placeholders of the entry.

Returns

string

The requested text or an empty string.

Exceptions

TemplateProcessingException

thrown if processing of the template fails.

ProcessTemplatedValue(CultureInfo, TextFormat, Func<string, int, object?>)

Processes the templated translation entry by substituting the placeholders with actual values and returns the final text.

public string ProcessTemplatedValue(CultureInfo culture, TextFormat textProcessingMode, Func<string, int, object?> getPlaceholderValueFunc)

Parameters

culture CultureInfo

The culture/locale for which the text is needed.

textProcessingMode TextFormat

The required text processing mode.

getPlaceholderValueFunc Func<string, int, object>

The function which will be called to obtain values for the placeholders.

Returns

string

The requested text or an empty string.

Exceptions

TemplateProcessingException

thrown if processing of the template fails.

ProcessTemplatedValue(CultureInfo, TextFormat, object)

Processes the templated translation entry by substituting the placeholders with actual values and returns the final text.

public string ProcessTemplatedValue(CultureInfo culture, TextFormat textProcessingMode, object placeholderValues)

Parameters

culture CultureInfo

The culture/locale for which the text is needed.

textProcessingMode TextFormat

The required text processing mode.

placeholderValues object

The values for the placeholders of the entry.

Returns

string

The requested text or an empty string.

Exceptions

TemplateProcessingException

thrown if processing of the template fails.

ProcessTemplatedValue(CultureInfo, TextFormat, params object?[])

Processes the templated translation entry by substituting the placeholders with actual values and returns the final text.

public string ProcessTemplatedValue(CultureInfo culture, TextFormat textProcessingMode, params object?[] placeholderValuesObjArray)

Parameters

culture CultureInfo

The culture/locale for which the text is needed.

textProcessingMode TextFormat

The required text processing mode.

placeholderValuesObjArray object[]

The values for the placeholders of the entry.

Returns

string

The requested text or an empty string.

Exceptions

TemplateProcessingException

thrown if processing of the template fails.

Unlock()

For internal use only.

public void Unlock()