Class BaseWriter
The basic writer class for specialized format writers. It defines the basic methods that should be implemented by all writers.
public abstract class BaseWriter
- Inheritance
-
BaseWriter
- Derived
- Inherited Members
Fields
ErrNoConfigInTranslationManager
The message of the exception thrown by WriteConfiguration(TranslationManager, Stream) when the translation manager has no default configuration.
protected const string ErrNoConfigInTranslationManager = "The translation manager does not have a configuration to save."
Field Value
ErrNoTranslationForCultureS1
The message of the exception thrown when the translation manager has no translation for a culture to be written. The format item is the name of the culture.
protected const string ErrNoTranslationForCultureS1 = "No translation found for culture {0}."
Field Value
ErrSingleFileFormatS1
The message of the exception thrown by WriteTranslations(TranslationManager, IReadOnlyCollection<CultureInfo>, Stream) of a format that holds one language per file. The format item is the FormatName of the writer.
protected const string ErrSingleFileFormatS1 = "The {0} format does not support multiple languages in one file. Use the WriteTranslation() method instead."
Field Value
Properties
ConfigExtension
Gets the extension of the configuration files of the format, with the leading dot (e.g., ".jsoncfg"), or an empty string if the writer does not write configuration files.
public abstract string ConfigExtension { get; }
Property Value
FormatName
Gets the name of the format (e.g., "JSON" or "RESX"), which is also used in error messages.
public abstract string FormatName { get; }
Property Value
TranslationExtension
Gets the extension of the translation files of the format, with the leading dot (e.g., ".json").
public abstract string TranslationExtension { get; }
Property Value
Methods
GetImmediateChild(string, string)
Gets the immediate child key from a parent and its descendant key.
protected static string? GetImmediateChild(string parentKey, string descendantKey)
Parameters
Returns
GetSectionAndKeyName(string)
Splits a hierarchical key at its last dot into the name of the section and the name of the key within the section.
protected static (string, string) GetSectionAndKeyName(string key)
Parameters
keystringThe key to split.
Returns
- (string escaped, string unescaped)
The part of
keybefore the last dot and the part after it, or an empty string andkeyif the key contains no dot.
GetSortedEntries(Translation)
Returns the entries of the translation in the order, in which they should be written.
protected static List<TranslationEntry> GetSortedEntries(Translation translation)
Parameters
translationTranslationThe translation whose entries are needed.
Returns
- List<TranslationEntry>
The entries in the order of the source file if the translation keeps it (OrderedEntries); otherwise, the entries sorted by their hierarchical keys.
InternalWriteTranslations(TranslationManager, IReadOnlyCollection<CultureInfo>, Stream)
Writes translations.
protected abstract void InternalWriteTranslations(TranslationManager translationManager, IReadOnlyCollection<CultureInfo> cultures, Stream stream)
Parameters
translationManagerTranslationManagerThe translation manager from which the translations should be picked.
culturesIReadOnlyCollection<CultureInfo>The list of cultures to write.
streamStreamThe stream to write the resulting file to.
IsParentKey(string, string)
Determines if the specified key is a parent of the given potential child key.
protected static bool IsParentKey(string parentKey, string childKey)
Parameters
Returns
- bool
True if parentKey is a parent of childKey; otherwise, false.
ShouldWriteReference(TranslationEntry)
Determines whether the entry should be written as a reference to another entry (@ followed by the reference) rather than as text.
protected virtual bool ShouldWriteReference(TranslationEntry entry)
Parameters
entryTranslationEntryThe entry to be written.
Returns
WriteConfiguration(TranslationManager, Stream)
Writes the default configuration of the translation manager (DefaultConfiguration) as a configuration file of the format.
public abstract void WriteConfiguration(TranslationManager translationManager, Stream stream)
Parameters
translationManagerTranslationManagerThe translation manager whose configuration should be written.
streamStreamThe stream to write the resulting file to.
Exceptions
- TlumachException
The translation manager has no default configuration, or the format does not support configuration files.
WriteTranslation(TranslationManager, CultureInfo, Stream)
Writes translations in the format that supports one language in one file.
public abstract void WriteTranslation(TranslationManager translationManager, CultureInfo culture, Stream stream)
Parameters
translationManagerTranslationManagerThe translation manager from which the translations should be picked.
cultureCultureInfoThe culture to write.
Set this parameter to InvariantCulture to signal that the default translation should be written.
streamStreamThe stream to write the resulting file to.
WriteTranslations(TranslationManager, IReadOnlyCollection<CultureInfo>, Stream)
Writes translations in the format that supports multiple languages in one file.
public abstract void WriteTranslations(TranslationManager translationManager, IReadOnlyCollection<CultureInfo> cultures, Stream stream)
Parameters
translationManagerTranslationManagerThe translation manager from which the translations should be picked.
culturesIReadOnlyCollection<CultureInfo>The list of cultures to write.
streamStreamThe stream to write the resulting file to.