DesignerTranslation

Manages translation of the designer workbook by reading translation tables (shapes, ranges, messages, dropdowns) from a dedicated translation worksheet. Provides factory creation with requirement validation, returns cached ITranslationObject instances scoped to each content type, and applies translations to an entire designer worksheet by updating shape text, named range values, and dropdown validations. The current language code is extracted from a language string (e.g. "FRA - Francais") and persisted as a worksheet-level HiddenName for cross-session persistence. All translation objects and name lists are cached for fast repeated access. Consumers interact through the IDesignerTranslation interface.

Depends on: TranslationObject, ITranslationObject, BetterArray, HiddenNames, IHiddenNames

Factory

Create #

create

Create a new DesignerTranslation instance from a translation worksheet

Signature:

Public Function Create(ByVal sh As Worksheet) As IDesignerTranslation

Factory method that validates all required ListObjects on the supplied worksheet, then constructs and returns a new instance through the IDesignerTranslation interface. Called on the predeclared instance.

Parameters:

  • sh: Worksheet. The translation worksheet containing T_tradShape, T_tradRange, T_tradMsg, T_tradDrop.

Returns: IDesignerTranslation. A fully initialised instance ready for use.


Translation Objects

TransObject #

trans-object

Translation object for a given content type

Signature:

Public Property Get TransObject(Optional ByVal trans As Byte = DesignerTranslationOfMessages) As ITranslationObject

Returns a cached ITranslationObject for the requested translation scope. Ensures caches are built using the current language code. Returns Nothing when no language code is configured.

Parameters:

  • trans: Optional Byte. TranslationType value selecting the content scope. Defaults to TranslationOfMessages.

Returns: ITranslationObject. The translation object for the requested scope.


Translation Application

TranslateDesigner #

translate-designer

Translate an entire designer worksheet

Signature:

Private Sub TranslateDesigner(ByVal mainsh As Worksheet, ByVal language As String)

Applies translations to all shapes, named ranges, and dropdown validations on the supplied worksheet. When a non-empty language string is provided (e.g. "FRA - Francais"), extracts the language code and persists it to the worksheet-level HiddenName. When the language string is empty, reads the stored language code. Exits silently when no language code is available.

Parameters:

  • mainsh: Worksheet. The designer worksheet to translate.
  • language: String. Language string in "CODE - Label" format. Pass vbNullString to use the stored language.

Message Lookup

TranslatedValue #

translation-msg

Get the translated value of a message code

Signature:

Private Function TranslatedValue(ByVal msgCode As String) As String

Returns the translated text for the supplied message code using the cached messages translation object. Ensures caches are built before lookup. Returns vbNullString when no language code is configured.

Parameters:

  • msgCode: String. The message code to translate.

Returns: String. The translated message text.


Internal members (not exported)

Factory

Wksh #

wksh

Translation worksheet

Signature:

Public Property Get Wksh() As Worksheet

Returns: Worksheet. The backing translation worksheet.


Wksh #

wksh-set

Assign the translation worksheet

Signature:

Public Property Set Wksh(ByVal sh As Worksheet)

Parameters:


Translation Objects

DesignerLanguage #

designer-language

Current designer language code

Signature:

Private Property Get DesignerLanguage() As String

Returns the cached language code if available, otherwise reads from the worksheet-level HiddenName. Returns an empty string when no language code is stored.

Returns: String. The current language code, or vbNullString when not set.


Translation Application

TranslateShapes #

translate-shapes

Apply shape translations on the target worksheet

Signature:

Private Sub TranslateShapes(ByVal mainsh As Worksheet)

Iterates over all shapes in the worksheet and replaces text content for shapes whose names appear in the cached shape names list. Preserves the original font name on each shape.

Parameters:


TranslateRanges #

translate-ranges

Apply named range translations on the target worksheet

Signature:

Private Sub TranslateRanges(ByVal mainsh As Worksheet)

Iterates over the cached range names and updates each matching named range on the worksheet with its translated value.

Parameters:


TranslateDropdowns #

translate-dropdowns

Apply dropdown validation translations on the target worksheet

Signature:

Private Sub TranslateDropdowns(ByVal mainsh As Worksheet)

Iterates over the cached dropdown names, deletes existing validation on each matching range, and creates a new list validation with the translated formula. Clears any existing cell content after applying the validation.

Parameters:


Language Code Management

ExtractLangCode #

extract-lang-code

Extract the language code from a language string

Signature:

Private Function ExtractLangCode(ByVal language As String) As String

Parses a language string in "CODE - Label" format (e.g. "FRA - Francais") and returns the code portion. If no separator is found, returns the trimmed input as-is.

Parameters:

Returns: String. The extracted language code.


UpdateLanguageCode #

update-language-code

Persist the language code to the worksheet-level HiddenName

Signature:

Private Sub UpdateLanguageCode(ByVal langCode As String)

Writes the language code to the TAG_DES_LANG HiddenName on the translation worksheet. Creates the name if it does not exist yet. Does not update the in-memory langCode field; EnsureCaches owns that so the cache-invalidation check remains correct.

Parameters:


WkshNames #

wksh-names

Cached HiddenNames accessor for the translation worksheet

Signature:

Private Property Get WkshNames() As IHiddenNames

Lazily creates and returns an IHiddenNames instance scoped to the translation worksheet.

Returns: IHiddenNames. The HiddenNames manager for the translation worksheet.


Cache Management

EnsureCaches #

ensure-caches

Build or refresh translation caches for the given language code

Signature:

Private Sub EnsureCaches(ByVal langCode As String)

When the caches are not yet built or the language code has changed, creates four TranslationObject instances and reads three name lists from the translation ListObjects. Skips rebuilding when the caches are already populated for the same language code.

Parameters:


Validation

CheckRequirements #

check-requirements

Validate that the worksheet has all required ListObjects

Signature:

Private Sub CheckRequirements(ByVal sh As Worksheet)

Checks that the supplied worksheet is not Nothing, then verifies the presence of four required ListObjects (T_tradShape, T_tradRange, T_tradMsg, T_tradDrop). Raises an error when any requirement is missing.

Parameters:


Error Handling

ThrowError #

throw-error

Raise a ProjectError-based exception

Signature:

Private Sub ThrowError(ByVal errNumber As Long, ByVal message As String)

Raises a VBA error using the supplied ProjectError code and message.

Parameters:


LoExists #

lo-exists

Verify that all listed ListObjects exist on a worksheet

Signature:

Private Sub LoExists(sh As Worksheet, ByVal loNames As BetterArray)

Iterates over the supplied BetterArray of table names and checks that each ListObject can be found on the given worksheet. Raises an error for the first missing table encountered.

Parameters:


Interface Implementation

IDesignerTranslation_TransObject #

Signature:

Private Property Get IDesignerTranslation_TransObject(Optional ByVal trans As Byte = DesignerTranslationOfMessages) As ITranslationObject

Delegated members satisfying the IDesignerTranslation contract. See the corresponding members above for full documentation.


Used in (12 file(s))