Class BaseParser
Inherited Members
Namespace: Tlumach.Base
Assembly: Tlumach.Base.dll
Syntax
public abstract class BaseParser
Properties
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.
Declaration
public static bool RecognizeFileRefs { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
UseDefaultFileForTranslations
Declaration
public virtual bool UseDefaultFileForTranslations { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
CanHandleExtension(string)
Checks whether this parser can handle a translation file with the given extension.
This method is not used for configuration files.
Declaration
public abstract bool CanHandleExtension(string fileExtension)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileExtension | The extension to check. |
Returns
| Type | Description |
|---|---|
| bool |
DecodeTextProcessingMode(string?)
Declaration
protected static TextFormat? DecodeTextProcessingMode(string? value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value |
Returns
| Type | Description |
|---|---|
| TextFormat? |
GetAbsolutePosition(string, int, int)
Declaration
protected static int GetAbsolutePosition(string text, int lineNumber, int linePosition)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | |
| int | lineNumber | |
| int | linePosition |
Returns
| Type | Description |
|---|---|
| int |
GetLocaleSeparatorChar()
Declaration
public virtual char GetLocaleSeparatorChar()
Returns
| Type | Description |
|---|---|
| char |
GetTextProcessingMode()
Declaration
protected virtual TextFormat GetTextProcessingMode()
Returns
| Type | Description |
|---|---|
| TextFormat |
InternalLoadTranslationStructure(string)
Loads the keys from the default translation file and builds a tree of keys.
Declaration
protected abstract TranslationTree? InternalLoadTranslationStructure(string content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | content | The content to parse. |
Returns
| Type | Description |
|---|---|
| TranslationTree | The constructed TranslationTree upon success or null otherwise. |
Exceptions
| Type | Condition |
|---|---|
| TextParseException | Gets thrown when parsing of a default translation file fails. |
LoadTranslation(string, CultureInfo?)
Loads the translation information from the file and returns a translation.
Declaration
public abstract Translation? LoadTranslation(string translationText, CultureInfo? culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | translationText | The text of the file to load. |
| CultureInfo | culture | 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. |
Returns
| Type | Description |
|---|---|
| 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.
Declaration
public TranslationTree? LoadTranslationStructure(string configFile, string? baseDirectory, out TranslationConfiguration? configuration)
Parameters
| Type | Name | Description |
|---|---|---|
| string | configFile | The configuration file to read. |
| string | baseDirectory | An optional directory to language files if |
| TranslationConfiguration | configuration | The loaded configuration or null if the method does not succeed. |
Returns
| Type | Description |
|---|---|
| TranslationTree | The constructed TranslationTree upon success or null otherwise. |
Exceptions
| Type | Condition |
|---|---|
| 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?)
Declaration
public abstract TranslationConfiguration? ParseConfiguration(string fileContent, Assembly? assembly)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileContent | |
| Assembly | assembly |
Returns
| Type | Description |
|---|---|
| TranslationConfiguration |
ParseConfigurationFile(Assembly, string)
Loads configuration from the file stored in assembly resource.
Declaration
public TranslationConfiguration? ParseConfigurationFile(Assembly assembly, string configFile)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | assembly | A reference to the assembly, from which the configuration file should be loaded. |
| string | configFile | 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
| Type | Description |
|---|---|
| TranslationConfiguration | The loaded configuration or null if loading failed. |
ParseConfigurationFile(string)
Loads configuration from the file.
Declaration
public TranslationConfiguration? ParseConfigurationFile(string configFile)
Parameters
| Type | Name | Description |
|---|---|---|
| string | configFile | The name of the file to load the configuration from. |
Returns
| Type | Description |
|---|---|
| TranslationConfiguration | The loaded configuration or null if loading failed. |
StringHasParameters(string, TextFormat)
Declaration
public static bool StringHasParameters(string inputText, TextFormat textProcessingMode)
Parameters
| Type | Name | Description |
|---|---|---|
| string | inputText | |
| TextFormat | textProcessingMode |
Returns
| Type | Description |
|---|---|
| bool |
ValidateConfiguration(TranslationConfiguration)
Declaration
protected virtual void ValidateConfiguration(TranslationConfiguration configuration)
Parameters
| Type | Name | Description |
|---|---|---|
| TranslationConfiguration | configuration |