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:33:56.334065+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 1d36778ed3ef747c |
Resources
Documentation: TranslateExtension Markup Extension
1. Purpose
This module provides a WPF MarkupExtension (TranslateExtension) to enable declarative, localized string resolution in XAML. It allows UI elements (e.g., TextBlock.Text, Button.Content) to bind to localized strings defined in StringResources by specifying a resource key. This supports internationalization of the Region of Interest (ROI) channels UI module by decoupling UI text from code and enabling culture-specific translations.
2. Public Interface
TranslateExtensionclass- Inherits:
System.Windows.Markup.MarkupExtension - Constructor:
public TranslateExtension(string key)- Initializes the extension with a resource key (
_key). - Throws no exceptions; invalid keys are handled at runtime (see Invariants and Gotchas).
- Initializes the extension with a resource key (
- Method:
public override object ProvideValue(IServiceProvider serviceProvider)- Returns the localized string corresponding to
_keyfromStringResources.ResourceManager. - If
_keyis null/empty → returns"#stringnotfound#". - If
_keyis non-empty but no matching resource exists → returns"#stringnotfound# <key>". - Otherwise → returns the resolved string (e.g.,
"Channel Name"for key"ChannelName").
- Returns the localized string corresponding to
- Inherits:
3. Invariants
_keyis immutable after construction (no setter, no modification).- The returned value is always a
string(per[MarkupExtensionReturnType(typeof(string))]). - Resource lookup behavior:
string.IsNullOrEmpty(_key)→ guaranteed to return"#stringnotfound#".- Non-empty
_keywith no matching resource → guaranteed to return"#stringnotfound# " + _key.
StringResources.ResourceManager.GetString(...)is used directly (no caching of individual lookups beyond .NET’s internalResourceManagercaching).
4. Dependencies
- Internal dependencies:
RegionOfInterestChannels.Resources.StringResources(strongly-typed resource class)System.Windows.Markup.MarkupExtension(WPF framework)System.Resources.ResourceManager(for runtime resource lookup)
- External dependencies:
- WPF runtime (for
MarkupExtensionand XAML integration). StringResources.resx(source file for localized strings; not included, but implied byStringResources.Designer.cs).
- WPF runtime (for
- Used by: XAML files in the
RegionOfInterestChannelsmodule (e.g.,TranslateExtensionis likely used as{local:Translate SomeKey}).
5. Gotchas
- No fallback to default culture: If
StringResources.Cultureis set, lookups respect it; otherwise, the thread’sCurrentUICultureis used. No explicit culture fallback logic is implemented. - Error strings are visible to users:
"#stringnotfound#"and"#stringnotfound# <key>"are returned verbatim—these are not silent failures and may appear in the UI if keys are misspelled or missing. - No validation of key existence at compile time: Keys are string literals; typos (e.g.,
"ChannelName"vs"ChannelName ") cause runtime errors. - Thread-safety: Relies on
StringResources.ResourceManager’s thread-safety (assumed per .NET docs), but no explicit synchronization is present. - No support for parameterized strings: While
StringResourcescontains format strings (e.g.,"Channel \"{0}\" has not been assigned..."),TranslateExtensiondoes not support passing arguments (e.g., nostring.Format-style interpolation). Users must handle formatting separately. - Auto-generated resource class:
StringResources.Designer.csis auto-generated; manual edits are overwritten. Resource keys must match exactly with.resxentries.
None identified beyond the above.