Class BaseParser
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
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
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
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
UseDefaultFileForTranslations
public virtual bool UseDefaultFileForTranslations { get; }
Property Value
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
utf8Bytesbyte[]
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
textstring
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
fileExtensionstringThe extension to check.
Returns
DecodeTextProcessingMode(string?)
protected static TextFormat? DecodeTextProcessingMode(string? value)
Parameters
valuestring
Returns
GetAbsolutePosition(string, int, int)
protected static int GetAbsolutePosition(string text, int lineNumber, int linePosition)
Parameters
Returns
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
Returns
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
Returns
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
contentstringThe content to parse.
textProcessingModeTextFormat?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
translationTextstringThe text of the file to load.
cultureCultureInfoAn 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.
textProcessingModeTextFormat?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
configFilestringThe configuration file to read.
baseDirectorystringAn optional directory to language files if
configFiledoes not contain a directory.configurationTranslationConfigurationThe 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
configFilestringThe configuration file to read.
baseDirectorystringAn optional directory to language files if
configFiledoes not contain a directory.configurationTranslationConfigurationThe loaded configuration or null if the method does not succeed.
defaultTranslationTranslationThe 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
Returns
ParseConfigurationFile(Assembly, string)
Loads configuration from the file stored in assembly resource.
public TranslationConfiguration? ParseConfigurationFile(Assembly assembly, string configFile)
Parameters
assemblyAssemblyA reference to the assembly, from which the configuration file should be loaded.
configFilestringThe 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
configFilestringThe 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
inputTextstringtextProcessingModeTextFormat
Returns
ValidateConfiguration(TranslationConfiguration)
protected virtual void ValidateConfiguration(TranslationConfiguration configuration)
Parameters
configurationTranslationConfiguration