Class BaseTranslationManager
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
translationConfigurationTranslationConfigurationThe configuration that specifies where to load translations from.
Fields
_defaultConfig
The configuration to use for loading translations.
protected TranslationConfiguration? _defaultConfig
Field Value
_defaultTranslation
The default translation that is used as a fallback.
protected Translation? _defaultTranslation
Field Value
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
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
Translations
protected Dictionary<string, Translation> Translations { get; }
Property Value
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
Methods
GetContent(Assembly?, string, CultureInfo)
protected virtual string GetContent(Assembly? assembly, string fileName, CultureInfo culture)
Parameters
assemblyAssemblyfileNamestringcultureCultureInfo
Returns
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
cultureCultureInfoThe culture to retrieve the translation for.
tryLoadMissingboolWhen 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
culturewas 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
assemblyAssemblyAn optional assembly where the file should be looked for.
filenamestringThe filename to load the data from.
hintPathstringAn optional path to the file. If set, the value is used only when opening based on the filename alone did not succeed.
usedFileNamestringBecomes set to the filename actually used if loading was successful. This filename may contain a path if loading was performed from the disk.
originalFilestringAn optional reference to the file, from which the translation was loaded.
Returns
InternalLoadTranslation(TranslationConfiguration, CultureInfo, bool)
Loads a translation from a file.
protected Translation? InternalLoadTranslation(TranslationConfiguration config, CultureInfo culture, bool tryLoadDefault)
Parameters
configTranslationConfigurationConfiguration information to use (contains an optional reference to the assembly and the filename(s).
cultureCultureInfoThe desired locale for which the file is needed.
tryLoadDefaultboolWhether 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
cultureCultureInfoThe 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
translationTextstringThe text to load the translation from.
parserBaseParserThe parser to use for parsing the
translationTexttext.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 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
cultureCultureInfo