Table of Contents

Class BaseWriter

Namespace
Tlumach.Writers
Assembly
Tlumach.Writers.dll

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

string

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

string

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

string

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

string

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

string

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

string

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

parentKey string

The parent key.

descendantKey string

The descendant key (child, grandchild, etc.).

Returns

string

The immediate child key name, or null if parentKey is not a parent of descendantKey.

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

key string

The key to split.

Returns

(string escaped, string unescaped)

The part of key before the last dot and the part after it, or an empty string and key if 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

translation Translation

The 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

translationManager TranslationManager

The translation manager from which the translations should be picked.

cultures IReadOnlyCollection<CultureInfo>

The list of cultures to write.

stream Stream

The 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

parentKey string

The potential parent key.

childKey string

The potential child key.

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

entry TranslationEntry

The entry to be written.

Returns

bool

true if the entry has no text but has a reference; otherwise, false.

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

translationManager TranslationManager

The translation manager whose configuration should be written.

stream Stream

The 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

translationManager TranslationManager

The translation manager from which the translations should be picked.

culture CultureInfo

The culture to write.

Set this parameter to InvariantCulture to signal that the default translation should be written.

stream Stream

The 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

translationManager TranslationManager

The translation manager from which the translations should be picked.

cultures IReadOnlyCollection<CultureInfo>

The list of cultures to write.

stream Stream

The stream to write the resulting file to.