Table of Contents

Class BaseParser

Namespace
Tlumach.Base
Assembly
Tlumach.Base.dll
public abstract class BaseParser
Inheritance
BaseParser
Derived
Inherited Members

Properties

KeepEntryOrder

Gets or sets the flag that makes Translation class preserve the order of entries as they are defined in the translation file. By default, entries are stored in a case-insensitive dictionary and their order is not preserved.

public static bool KeepEntryOrder { get; set; }

Property Value

bool

PopulateKeyLocations

Gets or sets the flag that tells the parser to build a list of key locations.

This property is used by the Generator and has no use otherwise.

public static bool PopulateKeyLocations { get; set; }

Property Value

bool

RecognizeFileRefs

Gets or sets the flag that tells parsers to recognize file references in translation texts.

A file reference is the text that starts with '@' character followed by the file name (with or without a path depending on other settings). If a reference is used, the text is taken from the referenced file.

public static bool RecognizeFileRefs { get; set; }

Property Value

bool

ThrowOnInvalidEscapeSequence

Gets or sets the flag that sets the parsers to throw an exception when an escape sequence is not recognized (e.g., "\q").

public static bool ThrowOnInvalidEscapeSequence { get; set; }

Property Value

bool

UseDefaultFileForTranslations

public virtual bool UseDefaultFileForTranslations { get; }

Property Value

bool

Methods

BuildByteLineStartsTable(byte[])

Builds a table of byte offsets for the start of each line in a UTF-8 byte array. Index 0 contains the byte offset of line 1, index 1 of line 2, etc.

protected static long[] BuildByteLineStartsTable(byte[] utf8Bytes)

Parameters

utf8Bytes byte[]

Returns

long[]

BuildLineStartsTable(string)

Builds a table of character offsets for the start of each line in a string. Index 0 contains the offset of line 1, index 1 contains the offset of line 2, etc.

protected static int[] BuildLineStartsTable(string text)

Parameters

text string

Returns

int[]

CanHandleExtension(string)

Checks whether this parser can handle a translation file with the given extension.

This method is not used for configuration files.

public abstract bool CanHandleExtension(string fileExtension)

Parameters

fileExtension string

The extension to check.

Returns

bool

true if the extension is supported and false otherwise.

DecodeTextProcessingMode(string?)

protected static TextFormat? DecodeTextProcessingMode(string? value)

Parameters

value string

Returns

TextFormat?

GetAbsolutePosition(string, int, int)

protected static int GetAbsolutePosition(string text, int lineNumber, int linePosition)

Parameters

text string
lineNumber int
linePosition int

Returns

int

GetLineAndColumnFromByteOffset(long[], long)

Converts a byte offset into 1-based line and column numbers using a byte line-starts table.

protected static (int Line, int Column) GetLineAndColumnFromByteOffset(long[] byteLineStarts, long byteOffset)

Parameters

byteLineStarts long[]
byteOffset long

Returns

(int Line, int Column)

GetLocaleSeparatorChar()

Used for internal needs.

public virtual char GetLocaleSeparatorChar()

Returns

char

The character, used to separate the base file name and the locale.

GetOffsetFromLineAndColumn(int[], int, int)

Converts a 1-based line number and column number to a character offset in a string, using a character line-starts table built by BuildLineStartsTable(string).

protected static int GetOffsetFromLineAndColumn(int[] lineStarts, int line, int col)

Parameters

lineStarts int[]
line int
col int

Returns

int

GetTextProcessingMode()

Used for internal needs.

protected virtual TextFormat GetTextProcessingMode()

Returns

TextFormat

The effective text processing mode.

InternalLoadTranslationStructure(string, TextFormat?)

Loads the keys from the default translation file and builds a tree of keys.

protected abstract TranslationTree? InternalLoadTranslationStructure(string content, TextFormat? textProcessingMode)

Parameters

content string

The content to parse.

textProcessingMode TextFormat?

The mode of processing of the text of the default file.

Returns

TranslationTree

The constructed TranslationTree upon success or null otherwise.

Exceptions

TextParseException

Gets thrown when parsing of a default translation file fails.

LoadTranslation(string, CultureInfo?, TextFormat?)

Loads the translation information from the file and returns a translation.

public abstract Translation? LoadTranslation(string translationText, CultureInfo? culture, TextFormat? textProcessingMode)

Parameters

translationText string

The text of the file to load.

culture CultureInfo

An optional reference to the locale, whose translation is to be loaded. Makes sense for CSV and TSV formats that may contain multiple translations in one file.

textProcessingMode TextFormat?

The mode of processing of the text of the translation file.

Returns

Translation

The loaded translation or null if loading failed.

LoadTranslationStructure(string, string?, out TranslationConfiguration?)

Parses the specified configuration file, then loads the keys from the specified default translation file and builds a tree of keys.

The files are loaded from the disk - this method is intended to be used by generators and converters.

public TranslationTree? LoadTranslationStructure(string configFile, string? baseDirectory, out TranslationConfiguration? configuration)

Parameters

configFile string

The configuration file to read.

baseDirectory string

An optional directory to language files if configFile does not contain a directory.

configuration TranslationConfiguration

The loaded configuration or null if the method does not succeed.

Returns

TranslationTree

The constructed TranslationTree upon success or null otherwise.

Exceptions

ParserLoadException

Gets thrown when loading of a configuration file or a default translation file fails.

TextFileParseException

Gets thrown when parsing of a default translation file fails.

LoadTranslationStructure(string, string?, out TranslationConfiguration?, out Translation?)

Parses the specified configuration file, then loads the keys from the specified default translation file and builds a tree of keys.

The files are loaded from the disk - this method is intended to be used by generators and converters.

public TranslationTree? LoadTranslationStructure(string configFile, string? baseDirectory, out TranslationConfiguration? configuration, out Translation? defaultTranslation)

Parameters

configFile string

The configuration file to read.

baseDirectory string

An optional directory to language files if configFile does not contain a directory.

configuration TranslationConfiguration

The loaded configuration or null if the method does not succeed.

defaultTranslation Translation

The parsed default translation.

Returns

TranslationTree

The constructed TranslationTree upon success or null otherwise.

Exceptions

ParserLoadException

Gets thrown when loading of a configuration file or a default translation file fails.

TextFileParseException

Gets thrown when parsing of a default translation file fails.

ParseConfiguration(string, Assembly?)

public abstract TranslationConfiguration? ParseConfiguration(string fileContent, Assembly? assembly)

Parameters

fileContent string
assembly Assembly

Returns

TranslationConfiguration

ParseConfigurationFile(Assembly, string)

Loads configuration from the file stored in assembly resource.

public TranslationConfiguration? ParseConfigurationFile(Assembly assembly, string configFile)

Parameters

assembly Assembly

A reference to the assembly, from which the configuration file should be loaded.

configFile string

The name of the file to load the configuration from. This name must include a subdirectory (if any) in resource format, such as "Translations.Data" if the original files' subdirectory is "Translations\Data" or "Translations/Data".

Returns

TranslationConfiguration

The loaded configuration or null if loading failed.

ParseConfigurationFile(string)

Loads configuration from the file.

public TranslationConfiguration? ParseConfigurationFile(string configFile)

Parameters

configFile string

The name of the file to load the configuration from.

Returns

TranslationConfiguration

The loaded configuration or null if loading failed.

StringHasParameters(string, TextFormat)

public static bool StringHasParameters(string inputText, TextFormat textProcessingMode)

Parameters

inputText string
textProcessingMode TextFormat

Returns

bool

ValidateConfiguration(TranslationConfiguration)

protected virtual void ValidateConfiguration(TranslationConfiguration configuration)

Parameters

configuration TranslationConfiguration