1.8 KiB
1.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
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
_keyisnullor empty, returns the constantNotFound("#stringnotfound#"). - Otherwise, calls
Strings.ResourceManager.GetString(_key)to retrieve the localized resource. - If the resource lookup returns
null, returnsNotFound + " " + _key(e.g.,"#stringnotfound# MyKey"). - If the resource is found, returns the localized string value.
3. Invariants
- Key immutability: The
_keyfield isreadonlyand set exactly once at construction. - Non-null return:
ProvideValuealways returns a non-nullstring(never returnsnullitself). - Fallback format: Missing resources are always identifiable by the `#stringnotfound