Class TranslationEntry
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
keystringThe key to which the translation entry corresponds.
textstringAn optional localized text of the translation entry that has been un-escaped if necessary.
escapedTextstringAn optional localized text of the translation entry that has not been un-escaped.
referencestringAn optional reference to an external file with the text.
keyLocationKeyLocationThe 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
ChangeReason
Gets or sets an optional reason for the last change. Used in XLIFF format.
public string? ChangeReason { get; set; }
Property Value
Comment
Gets or sets an optional comment of the entry.
public string? Comment { get; set; }
Property Value
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
Context
Gets or sets an optional description of the context.
public string? Context { get; set; }
Property Value
Description
Gets or sets an optional description of the entry.
public string? Description { get; set; }
Property Value
Empty
Gets a static instance that represents an empty entry.
public static TranslationEntry Empty { get; }
Property Value
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
Key
Gets the original key of the entry.
public string Key { get; }
Property Value
KeyLocated
public KeyLocation? KeyLocated { get; }
Property Value
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
Placeholders
Gets an optional collection of placeholder descriptions.
public List<Placeholder>? Placeholders { get; }
Property Value
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
Screen
Gets or sets an optional reference to a screenshot of the entry.
public string? Screen { get; set; }
Property Value
SourceText
Gets or sets an optional original text that was translated.
public string? SourceText { get; set; }
Property Value
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
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
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
Video
Gets or sets an optional reference to a video of the entry.
public string? Video { get; set; }
Property Value
Methods
AddPlaceholder(Placeholder)
public void AddPlaceholder(Placeholder placeholder)
Parameters
placeholderPlaceholder
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
parametersList<(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.
textProcessingModeTextFormatThe text-processing mode that drives placeholder parsing.
includeCultureInfoboolmethodNamestringThe 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
inputTextstringtextProcessingModeTextFormat
Returns
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
leftTranslationEntryThe first TranslationEntry to compare.
rightTranslationEntryThe 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
cultureCultureInfoThe culture/locale for which the text is needed.
textProcessingModeTextFormatThe required text processing mode.
placeholderValuesDictIDictionary<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
cultureCultureInfoThe culture/locale for which the text is needed.
textProcessingModeTextFormatThe required text processing mode.
placeholderValuesOrderedDictOrderedDictionaryThe 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
cultureCultureInfoThe culture/locale for which the text is needed.
textProcessingModeTextFormatThe required text processing mode.
getPlaceholderValueFuncFunc<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
cultureCultureInfoThe culture/locale for which the text is needed.
textProcessingModeTextFormatThe required text processing mode.
placeholderValuesobjectThe 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
cultureCultureInfoThe culture/locale for which the text is needed.
textProcessingModeTextFormatThe required text processing mode.
placeholderValuesObjArrayobject[]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()