Table of Contents

Class BaseTranslationManager

Namespace
Tlumach.Base
Assembly
Tlumach.Base.dll

The base class shared between the main class hierarchy and Generator.

public class BaseTranslationManager
Inheritance
BaseTranslationManager
Derived
Inherited Members

Constructors

BaseTranslationManager()

protected BaseTranslationManager()

BaseTranslationManager(TranslationConfiguration)

Initializes a new instance of the BaseTranslationManager class.

This constructor creates a translation manager based on the specified configuration. Such translation manager can be used to simplify access to translations when translation units are not used - an application simply calls the GetValue method and species the key and, optionally, the culture.

public BaseTranslationManager(TranslationConfiguration translationConfiguration)

Parameters

translationConfiguration TranslationConfiguration

The configuration that specifies where to load translations from.

Fields

_defaultConfig

The configuration to use for loading translations.

protected TranslationConfiguration? _defaultConfig

Field Value

TranslationConfiguration

_defaultTranslation

The default translation that is used as a fallback.

protected Translation? _defaultTranslation

Field Value

Translation

Properties

DefaultConfiguration

Gets the configuration used by this Translation Manager. May be empty if it was not set explicitly or by the generated class (when the Generator is used).

public TranslationConfiguration? DefaultConfiguration { get; }

Property Value

TranslationConfiguration

LoadFromDisk

Gets or sets the indicator that tells TranslationManager to attempt to locate translation files on the disk.

public bool LoadFromDisk { get; set; }

Property Value

bool

Translations

protected Dictionary<string, Translation> Translations { get; }

Property Value

Dictionary<string, Translation>

TranslationsDirectory

Gets or sets the directory in which translations files are looked for.

When LoadFromDisk is disabled, this value is used when trying to load the translations from the assembly. When LoadFromDisk is enabled, this value is also used when trying to locate translation files on the disk.

This property is a hint for the manager, which affects loading of secondary translation files. When a configuration is loaded via the BaseTranslationManager constructor, specify the directory in the name of the configuration file.

public string TranslationsDirectory { get; set; }

Property Value

string

Methods

GetContent(Assembly?, string, CultureInfo)

protected virtual string GetContent(Assembly? assembly, string fileName, CultureInfo culture)

Parameters

assembly Assembly
fileName string
culture CultureInfo

Returns

string

GetTranslation(CultureInfo, bool)

Returns the translation object for the given culture if one exists. Optionally tries to load a missing translation.

public Translation? GetTranslation(CultureInfo culture, bool tryLoadMissing = false)

Parameters

culture CultureInfo

The culture to retrieve the translation for.

tryLoadMissing bool

When set to true, specifies that if a translation is not loaded, it should be search for and loaded.

Returns

Translation

The Translation instance if one was found and null otherwise or if culture was null.

InternalLoadFileContent(Assembly?, string, string?, ref string?, string?)

Loads content of the file.

protected string? InternalLoadFileContent(Assembly? assembly, string filename, string? hintPath, ref string? usedFileName, string? originalFile = null)

Parameters

assembly Assembly

An optional assembly where the file should be looked for.

filename string

The filename to load the data from.

hintPath string

An optional path to the file. If set, the value is used only when opening based on the filename alone did not succeed.

usedFileName string

Becomes set to the filename actually used if loading was successful. This filename may contain a path if loading was performed from the disk.

originalFile string

An optional reference to the file, from which the translation was loaded.

Returns

string

File content if the file was found and loaded and null otherwise.

InternalLoadTranslation(TranslationConfiguration, CultureInfo, bool)

Loads a translation from a file.

protected Translation? InternalLoadTranslation(TranslationConfiguration config, CultureInfo culture, bool tryLoadDefault)

Parameters

config TranslationConfiguration

Configuration information to use (contains an optional reference to the assembly and the filename(s).

culture CultureInfo

The desired locale for which the file is needed.

tryLoadDefault bool

Whether the default file should be tried.

Returns

Translation

A translation if one was found and loaded and null otherwise.

LoadTranslation(CultureInfo)

Locates and loads the translation.

public Translation? LoadTranslation(CultureInfo culture)

Parameters

culture CultureInfo

The culture, for which the translation is needed.

Returns

Translation

A Translation instance or null if a translation could not be loaded.

LoadTranslation(string, BaseParser, CultureInfo?, TextFormat?)

Loads the translation from the given text using the specified parser.

public static Translation? LoadTranslation(string translationText, BaseParser parser, CultureInfo? culture, TextFormat? textProcessingMode)

Parameters

translationText string

The text to load the translation from.

parser BaseParser

The parser to use for parsing the translationText text.

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 required text processing mode.

Returns

Translation

A Translation instance or null if the parser failed to load the translation.

Exceptions

GenericParserException

and its descendants are thrown if parsing fails due to errors in format of the input.

TranslationFileNotFound(CultureInfo)

protected virtual Translation TranslationFileNotFound(CultureInfo culture)

Parameters

culture CultureInfo

Returns

Translation