Table of Contents

Class TranslationConfiguration

Namespace
Tlumach.Base
Assembly
Tlumach.Base.dll

Contains the configuration built when parsing source files and passed to the translation manager by the translation unit.

public class TranslationConfiguration
Inheritance
TranslationConfiguration
Inherited Members

Constructors

TranslationConfiguration(Assembly?, string, string?, string?, string?, TextFormat)

Initializes a new instance of the TranslationConfiguration class.

Used by configuration parsers.

public TranslationConfiguration(Assembly? assembly, string defaultFile, string? @namespace, string? className, string? defaultFileLocale, TextFormat textProcessingMode)

Parameters

assembly Assembly

An optional assembly that contains translations. May be empty if files are loaded from the disk.

defaultFile string

a reference to the default file for the translation.

namespace string

The namespace to which the class with generated translation units belongs.

className string

The name of the class with generated translation units.

defaultFileLocale string

The locale specified in the file (when supported by the file format).

textProcessingMode TextFormat

specifies how the translation entries should be parsed to determine whether they contain placeholders and to replace these placeholders with real values. See TextFormat for details.

TranslationConfiguration(Assembly?, string, string?, string?, string?, TextFormat, bool, bool, bool)

Initializes a new instance of the TranslationConfiguration class.

Used by configuration parsers.

public TranslationConfiguration(Assembly? assembly, string defaultFile, string? @namespace, string? className, string? defaultFileLocale, TextFormat textProcessingMode, bool delayedUnitCreation, bool onlyDeclareKeys, bool createFilledMethods)

Parameters

assembly Assembly

An optional assembly that contains translations. May be empty if files are loaded from the disk.

defaultFile string

a reference to the default file for the translation.

namespace string

The namespace to which the class with generated translation units belongs.

className string

The name of the class with generated translation units.

defaultFileLocale string

The locale specified in the file (when supported by the file format).

textProcessingMode TextFormat

Specifies how the translation entries should be parsed to determine whether they contain placeholders and to replace these placeholders with real values. See TextFormat for details.

delayedUnitCreation bool

Tells the generator to generate code for delayed creation of generated translation units.

onlyDeclareKeys bool

Tells the generator to skip generation of translation units and just add key constants.

createFilledMethods bool

Tells the generator to create descendant classes with "Filled" methods for entries with placeholders in the text.

TranslationConfiguration(Assembly?, string, string?, string?, string?, TextFormat, bool, bool, bool, bool, string?, string?)

Initializes a new instance of the TranslationConfiguration class.

Used by configuration parsers.

public TranslationConfiguration(Assembly? assembly, string defaultFile, string? @namespace, string? className, string? defaultFileLocale, TextFormat textProcessingMode, bool delayedUnitCreation, bool onlyDeclareKeys, bool createFilledMethods, bool createStringAccessors, string? stringAccessorsClass, string? stringAccessorsCulture)

Parameters

assembly Assembly

An optional assembly that contains translations. May be empty if files are loaded from the disk.

defaultFile string

a reference to the default file for the translation.

namespace string

The namespace to which the class with generated translation units belongs.

className string

The name of the class with generated translation units.

defaultFileLocale string

The locale specified in the file (when supported by the file format).

textProcessingMode TextFormat

Specifies how the translation entries should be parsed to determine whether they contain placeholders and to replace these placeholders with real values. See TextFormat for details.

delayedUnitCreation bool

Tells the generator to generate code for delayed creation of generated translation units.

onlyDeclareKeys bool

Tells the generator to skip generation of translation units and just add key constants.

createFilledMethods bool

Tells the generator to create descendant classes with "Filled" methods for entries with placeholders in the text.

createStringAccessors bool

Tells the generator to generate a nested class with string accessors of the keys.

stringAccessorsClass string

The name of the class with string accessors. Pass null to use the default name.

stringAccessorsCulture string

The culture read by the string accessors, either "manager" or "ambient". Pass null to use the default.

TranslationConfiguration(Assembly?, string, string?, TextFormat)

Initializes a new instance of the TranslationConfiguration class.

Usable by the code that does not use TranslationUnits.

public TranslationConfiguration(Assembly? assembly, string defaultFile, string? defaultFileLocale, TextFormat textProcessingMode)

Parameters

assembly Assembly

An optional assembly that contains translations. May be empty if files are loaded from the disk.

defaultFile string

a reference to the default file for the translation.

defaultFileLocale string

The locale specified in the file (when supported by the file format).

textProcessingMode TextFormat

specifies how the translation entries should be parsed to determine whether they contain placeholders and to replace these placeholders with real values. See TextFormat for details.

Fields

KEY_ATTR_NAME

The name of the "name" attribute in the translations section in the configuration file (XML only).

public const string KEY_ATTR_NAME = "name"

Field Value

string

KEY_CREATE_FILLED_METHODS

When set to true, indicates that key-specific translation unit classes should be created for keys with placeholders. Those classes contain "Filled()" methods.

public const string KEY_CREATE_FILLED_METHODS = "createFilledMethods"

Field Value

string

KEY_CREATE_STRING_ACCESSORS

When set to true, indicates that a nested class with string accessors should be generated in the generated class and in every generated group class. The accessors let the attributes that localize through a resource type and the name of a property, such as DisplayAttribute, use a class generated by Tlumach. This option is ignored when KEY_ONLY_DECLARE_KEYS is set.

public const string KEY_CREATE_STRING_ACCESSORS = "createStringAccessors"

Field Value

string

KEY_DEFAULT_FILE

The name of the default file (the one that will be loaded by default).

public const string KEY_DEFAULT_FILE = "defaultFile"

Field Value

string

KEY_DEFAULT_LOCALE

The name of the locale of the text in the default file.

public const string KEY_DEFAULT_LOCALE = "defaultLocale"

Field Value

string

KEY_DEFAULT_LOCALE_ALIAS

The deprecated alias of KEY_DEFAULT_LOCALE. It matches the name of the DefaultFileLocale property and was advertised by the documentation, so it is still accepted when reading configuration files. KEY_DEFAULT_LOCALE takes precedence when both are present, and only KEY_DEFAULT_LOCALE is ever written.

public const string KEY_DEFAULT_LOCALE_ALIAS = "defaultFileLocale"

Field Value

string

KEY_DELAYED_UNITS_CREATION

When set to true, indicates that creation of generated translation units must be delayed until they are accessed.

public const string KEY_DELAYED_UNITS_CREATION = "delayedUnitsCreation"

Field Value

string

KEY_GENERATED_CLASS

The name of the class that the generator puts to the generated source code.

public const string KEY_GENERATED_CLASS = "generatedClass"

Field Value

string

KEY_GENERATED_NAMESPACE

The name of the namespace that the generator puts to the generated source code.

public const string KEY_GENERATED_NAMESPACE = "generatedNamespace"

Field Value

string

KEY_LOCALE

The name of an element in the translations section in the configuration file (XML only).

public const string KEY_LOCALE = "locale"

Field Value

string

KEY_ONLY_DECLARE_KEYS

When set to true, indicates that translation units should not be generated, and only string keys should be declared.

public const string KEY_ONLY_DECLARE_KEYS = "onlyDeclareKeys"

Field Value

string

KEY_SECTION_TRANSLATIONS

The name of the translations section in the configuration file.

public const string KEY_SECTION_TRANSLATIONS = "translations"

Field Value

string

KEY_SECTION_TRANSLATIONS_DOT

The name of the translations section in the configuration file suffixed with a dot.

public static readonly string KEY_SECTION_TRANSLATIONS_DOT

Field Value

string

KEY_STRING_ACCESSORS_CLASS

The name of the class with string accessors generated because of KEY_CREATE_STRING_ACCESSORS. The default is "Texts".

public const string KEY_STRING_ACCESSORS_CLASS = "stringAccessorsClass"

Field Value

string

KEY_STRING_ACCESSORS_CULTURE

The culture read by the string accessors generated because of KEY_CREATE_STRING_ACCESSORS. Set it to "ambient" to read the culture of the thread, which is what a web application that localizes requests needs; the default, "manager", reads the culture of the translation manager.

public const string KEY_STRING_ACCESSORS_CULTURE = "stringAccessorsCulture"

Field Value

string

KEY_TEXT_PROCESSING_MODE

The name of the class that the generator puts to the generated source code.

public const string KEY_TEXT_PROCESSING_MODE = "textProcessingMode"

Field Value

string

KEY_TRANSLATION_ASTERISK

The optional notation to specify the file, from which all translations not listed specifically are loaded. This values gets converted to "other" in the code but may be used for clarity in the configuration files.

public const string KEY_TRANSLATION_ASTERISK = "*"

Field Value

string

KEY_TRANSLATION_OTHER

The optional notation to specify the file, from which all translations not listed specifically are loaded.

public const string KEY_TRANSLATION_OTHER = "other"

Field Value

string

Properties

Assembly

Gets a reference to the assembly, in which the generated file resides.

public Assembly? Assembly { get; }

Property Value

Assembly

ClassName

Gets the name of the class that is generated by the generator.

public string? ClassName { get; }

Property Value

string

CreateFilledMethods

Gets the indicator used by the generator to create descendant classes with "Filled" methods for entries with placeholders in the text.

public bool CreateFilledMethods { get; }

Property Value

bool

CreateStringAccessors

Gets the indicator used by the generator to generate a nested class with string accessors in the generated class and in every generated group class.

The accessors are static properties of the type string, one per key, which is what the attributes that localize through a resource type and the name of a property, such as DisplayAttribute, require. This option is ignored when OnlyDeclareKeys is set.

public bool CreateStringAccessors { get; }

Property Value

bool

DefaultFile

Gets a reference to the default file. The value may be a filename with or without a path, but it must include an extension, so that the proper parser can be selected.

public string DefaultFile { get; }

Property Value

string

DefaultFileLocale

Gets a locale of the default file, if the locale was present in this file.

public string? DefaultFileLocale { get; set; }

Property Value

string

DelayedUnitsCreation

Gets the indicator used by the generator to generate the code that delays creation of generated translation units until they are accessed.

public bool DelayedUnitsCreation { get; }

Property Value

bool

DirectoryHint

Gets or sets the hint path that can be used when locating translation files.

When configuration is loaded by the constructors of the TranslationManager class, this property is set to whatever directory is specified in the configFile parameter of the constructor, but an application is free to change it.

Another way to specify the hint is to set the TranslationsDirectory property of TranslationManager.

public string? DirectoryHint { get; set; }

Property Value

string

Empty

public static TranslationConfiguration Empty { get; }

Property Value

TranslationConfiguration

Namespace

Gets the namespace, to which the generated class should belong.

public string? Namespace { get; }

Property Value

string

OnlyDeclareKeys

Gets the indicator used by the generator to not declare TranslationUnits and only declare string constants with keys.

public bool OnlyDeclareKeys { get; }

Property Value

bool

StringAccessorsClass

Gets the name of the class with string accessors generated because of CreateStringAccessors. When this property is empty, the generator uses "Texts".

public string? StringAccessorsClass { get; }

Property Value

string

StringAccessorsCulture

Gets the culture read by the string accessors generated because of CreateStringAccessors. When this property is set to "ambient", the accessors read the culture of the thread; otherwise they read the culture of the translation manager.

public string? StringAccessorsCulture { get; }

Property Value

string

TextProcessingMode

Gets the text processing mode used for parsing (it will be used for processing templates too).

public TextFormat? TextProcessingMode { get; }

Property Value

TextFormat?

Translations

Gets the list of individual translation items covered by the configuration. This list may be empty or incomplete, in which case, the library will use heuristics to determine the filename to load the translation from.

public Dictionary<string, string> Translations { get; }

Property Value

Dictionary<string, string>

Methods

GetEscapeModeFullName()

public string GetEscapeModeFullName()

Returns

string