init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/Resources/TranslateExtension.cs
|
||||
- DataPRO/Modules/RegionOfInterest/RegionOfInterestChannels/Resources/StringResources.Designer.cs
|
||||
generated_at: "2026-04-16T04:33:56.334065+00:00"
|
||||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||||
schema_version: 1
|
||||
sha256: "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
|
||||
- **`TranslateExtension` class**
|
||||
- **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*).
|
||||
- **Method**: `public override object ProvideValue(IServiceProvider serviceProvider)`
|
||||
- Returns the localized string corresponding to `_key` from `StringResources.ResourceManager`.
|
||||
- If `_key` is null/empty → returns `"#stringnotfound#"`.
|
||||
- If `_key` is non-empty but no matching resource exists → returns `"#stringnotfound# <key>"`.
|
||||
- Otherwise → returns the resolved string (e.g., `"Channel Name"` for key `"ChannelName"`).
|
||||
|
||||
### 3. Invariants
|
||||
- `_key` is 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 `_key` with no matching resource → guaranteed to return `"#stringnotfound# " + _key`.
|
||||
- `StringResources.ResourceManager.GetString(...)` is used directly (no caching of individual lookups beyond .NET’s internal `ResourceManager` caching).
|
||||
|
||||
### 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 `MarkupExtension` and XAML integration).
|
||||
- `StringResources.resx` (source file for localized strings; not included, but implied by `StringResources.Designer.cs`).
|
||||
- **Used by**: XAML files in the `RegionOfInterestChannels` module (e.g., `TranslateExtension` is likely used as `{local:Translate SomeKey}`).
|
||||
|
||||
### 5. Gotchas
|
||||
- **No fallback to default culture**: If `StringResources.Culture` is set, lookups respect it; otherwise, the thread’s `CurrentUICulture` is 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 `StringResources` contains format strings (e.g., `"Channel \"{0}\" has not been assigned..."`), `TranslateExtension` does *not* support passing arguments (e.g., no `string.Format`-style interpolation). Users must handle formatting separately.
|
||||
- **Auto-generated resource class**: `StringResources.Designer.cs` is auto-generated; manual edits are overwritten. Resource keys must match exactly with `.resx` entries.
|
||||
|
||||
None identified beyond the above.
|
||||
Reference in New Issue
Block a user