Passa al contenuto principale

Class TranslationDictionary

Namespace: TecnoPack.TranslationsManager.Model
Assembly: CO0002_Templ_FlowpackHMI_V00_26_M.dll

Represents a translation dictionary stored as a two-dimensional string array.

public sealed class TranslationDictionary

Inheritance

object ← TranslationDictionary

Remarks

The first row contains the language headers.
The first column contains translation keys.

Constructors

TranslationDictionary(string[,])

Initializes a new instance of the class.

public TranslationDictionary(string[,] data)

Parameters

data string[,]

The 2D string array containing the dictionary.

Exceptions

ArgumentNullException

Thrown when data is null.

Properties

Columns

Gets the number of columns in the dictionary.

public int Columns { get; }

Property Value

int

Data

Gets the underlying 2D string array.

public string[,] Data { get; }

Property Value

string[,]

Rows

Gets the number of rows in the dictionary.

public int Rows { get; }

Property Value

int

this[int, int]

Gets the value stored at the specified row and column of the underlying two-dimensional Data array.

public string this[int row, int col] { get; }

Property Value

string

Exceptions

IndexOutOfRangeException

Thrown if row or col is outside the bounds of the Data array.

Methods

MergeDictionaries(string[,], string[,])

Merges translation values from an imported dictionary into an existing dictionary while preserving the existing structure and columns.

public static string[,] MergeDictionaries(string[,] existing, string[,] imported)

Parameters

existing string[,]

The existing dictionary represented as a two-dimensional array, where:

  • Row 0 contains the language headers.
  • Column 0 contains the translation keys.
  • Every other cell contains a translation value.

imported string[,]

The imported dictionary in the same layout format as existing. Only languages and keys that already exist in existing will be merged.

Returns

string[,]

A new two-dimensional array containing the merged dictionary:

  • Keys present in imported but not in existing are ignored.

  • Languages (columns) that do not appear in the existing dictionary are ignored.

  • Non-empty imported values overwrite the corresponding existing values. Empty or whitespace imported values are skipped.

Remarks

The method performs a column-aligned merge using the language names in the header row. If a language exists in the imported dictionary but not in the existing dictionary, it is skipped.

Rows are merged based on the key in column 0. Keys in the imported dictionary that do not appear in the existing dictionary are ignored, ensuring no new rows are added.

The result contains the same dimensions as existing.

Exceptions

ArgumentNullException

Thrown if existing or imported is null.

ArgumentException

Thrown if either array has fewer than two columns or fewer than one row.

RemoveCompleteTranslations()

Removes rows that are invalid or redundant based on translation completeness.

public void RemoveCompleteTranslations()

Remarks

A row (except for the header row 0) is removed when one of the following is true:

  • The key in column 0 is empty or whitespace.
  • All translation columns (columns ≥ 1) contain non-empty values (fully translated).
  • All translation columns (columns ≥ 1) are empty or whitespace (no translations present).
The header row is always preserved.
After filtering, the underlying array is rebuilt and assigned back.