4.0 KiB
4.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:50:59.405186+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 8602aa2c75632a3b |
Resources
Documentation: TranslateExtension Markup Extension
1. Purpose
The TranslateExtension class is a WPF MarkupExtension used to resolve localized string resources at XAML runtime. It enables declarative binding to localized strings in UI markup by accepting a resource key and returning the corresponding localized value from the StringResources strongly-typed resource class. This allows UI text to be localized without hardcoding strings in XAML, supporting multi-language deployments of the diagnostics module.
2. Public Interface
TranslateExtension(string key)
- Signature:
public TranslateExtension(string key) - Behavior: Constructor. Stores the provided resource key for later lookup. Does not perform validation beyond null/empty checks during
ProvideValue.
ProvideValue(IServiceProvider serviceProvider)
- Signature:
public override object ProvideValue(IServiceProvider serviceProvider) - Behavior:
- If
_keyisnullor empty, returns"#stringnotfound#". - Otherwise, attempts to retrieve the string value from
StringResources.ResourceManager.GetString(_key). - If the resource is not found (i.e.,
GetStringreturnsnull), returns"#stringnotfound# " + _key(note the trailing space). - Returns a
string(as indicated by[MarkupExtensionReturnType(typeof(string))]).
- If
3. Invariants
_keyis immutable after construction (stored in areadonlyfield).- The returned value is always a
string. - Missing or empty keys always yield
"#stringnotfound#"(no concatenation with key). - Missing resources always yield
"#stringnotfound# <key>"(with a space between the prefix and key). - No exceptions are thrown during
ProvideValue—errors are silently handled via fallback strings. - Resource lookup uses the default
ResourceManagerinstance and current UI culture (unless overridden viaStringResources.Culture).
4. Dependencies
Dependencies of TranslateExtension:
System.Windows.Markup.MarkupExtension(base class, part of WPF).Diagnostics.Resources.StringResources(specifically itsResourceManagerproperty andGetString(string)method).System(forstring.IsNullOrEmpty,object.ReferenceEquals, etc.).
Dependencies on TranslateExtension:
- XAML files in the diagnostics module (e.g.,
.xamlfiles) that use{local:Translate KeyName}syntax to bind UI text. StringResources.Designer.csmust be compiled and available at runtime (auto-generated; relies on corresponding.resxfile, not visible here).
5. Gotchas
- No null-safety for
_keybeyond emptiness: Passingnullas_keyis allowed in the constructor but results in"#stringnotfound#"at runtime. - Ambiguous fallbacks: Both missing keys and empty keys produce
"#stringnotfound#", making debugging harder without inspecting the key itself. - Hardcoded prefix: The
"#stringnotfound#"string is hardcoded and not configurable. If this prefix appears in actual resources, it may cause confusion. - No caching of resolved values: Each
ProvideValuecall re-invokesResourceManager.GetString, which may have performance implications in high-frequency scenarios (thoughResourceManageritself caches internally). - Culture dependency: Behavior depends on the current UI thread’s
Culture(viaStringResources.Culture). If the UI culture changes dynamically, existing bindings may not update unless re-evaluated. - No compile-time key validation: Typos in XAML resource keys (e.g.,
{local:Translate Channles}) will only surface at runtime as"#stringnotfound# Channles".
None identified beyond the above.