Files
DP44/docs/ai/Common/DTS.Common/Strings.md
2026-04-17 14:55:32 -04:00

1.8 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common/Strings/TranslateExtension.cs
2026-04-17T15:40:47.154014+00:00 zai-org/GLM-5-FP8 1 5ba9d7fe887a2bf3

Documentation: TranslateExtension.cs

1. Purpose

This module provides a XAML markup extension for runtime string localization in WPF applications. It enables declarative resource lookup directly in XAML markup, allowing UI elements to reference localized strings by key rather than hardcoding values. The extension bridges the application's resource management system with XAML data binding infrastructure.


2. Public Interface

TranslateExtension Class

Inherits from: MarkupExtension
Attribute: [MarkupExtensionReturnType(typeof(string))]

Constructor

public TranslateExtension(string key)

Creates a new instance of the extension with the specified resource key. The key is stored in a private readonly field _key and cannot be modified after construction.

Method: ProvideValue

public override object ProvideValue(IServiceProvider serviceProvider)

Returns the localized string for the key provided at construction.

Behavior:

  • If _key is null or empty, returns the constant NotFound ("#stringnotfound#").
  • Otherwise, calls Strings.ResourceManager.GetString(_key) to retrieve the localized resource.
  • If the resource lookup returns null, returns NotFound + " " + _key (e.g., "#stringnotfound# MyKey").
  • If the resource is found, returns the localized string value.

3. Invariants

  • Key immutability: The _key field is readonly and set exactly once at construction.
  • Non-null return: ProvideValue always returns a non-null string (never returns null itself).
  • Fallback format: Missing resources are always identifiable by the `#stringnotfound