init
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
---
|
||||
source_files:
|
||||
- DataPRO/Modules/TestSetups/TestSetupsList/Resources/TranslateExtension.cs
|
||||
- DataPRO/Modules/TestSetups/TestSetupsList/Resources/StringResources.Designer.cs
|
||||
generated_at: "2026-04-16T04:51:19.579629+00:00"
|
||||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||||
schema_version: 1
|
||||
sha256: "9ca0cf52c1c54e32"
|
||||
---
|
||||
|
||||
# Resources
|
||||
|
||||
## Documentation: `TranslateExtension` Markup Extension
|
||||
|
||||
---
|
||||
|
||||
### 1. Purpose
|
||||
|
||||
The `TranslateExtension` class is a WPF `MarkupExtension` used to enable localized string binding in XAML. It resolves resource keys (e.g., `"Name"`, `"Description"`) to their corresponding localized string values at runtime by querying the strongly-typed `StringResources` class. This allows UI elements (e.g., `TextBlock.Text`, `HeaderedContentControl.Header`) to display culture-specific text without hardcoding strings, supporting internationalization of the TestSetupsList module.
|
||||
|
||||
---
|
||||
|
||||
### 2. Public Interface
|
||||
|
||||
#### `TranslateExtension` class
|
||||
|
||||
- **Constructor**
|
||||
```csharp
|
||||
public TranslateExtension(string key)
|
||||
```
|
||||
- **Parameters**:
|
||||
- `key`: The resource key (e.g., `"Name"`, `"LastModifiedBy"`) used to look up a localized string in `StringResources`.
|
||||
- **Behavior**: Stores the key for later resolution during `ProvideValue`.
|
||||
|
||||
- **`ProvideValue` method**
|
||||
```csharp
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
```
|
||||
- **Returns**:
|
||||
- If `_key` is `null` or empty → `"#stringnotfound#"`
|
||||
- If `StringResources.ResourceManager.GetString(_key)` returns a non-null value → that string
|
||||
- Otherwise → `"#stringnotfound# " + _key` (e.g., `"#stringnotfound# UnknownKey"`)
|
||||
- **Behavior**: Performs the actual resource lookup. Does *not* use the `serviceProvider` parameter (per source).
|
||||
|
||||
---
|
||||
|
||||
### 3. Invariants
|
||||
|
||||
- `_key` is immutable after construction (no setter, no modification in `ProvideValue`).
|
||||
- Resource keys are expected to match *exact* keys in the `.resx` file (e.g., `"Name"`, `"PreTriggerSeconds"`), case-sensitive.
|
||||
- The fallback string `"#stringnotfound#"` is hardcoded and used for both missing keys and empty keys.
|
||||
- `StringResources.ResourceManager.GetString(_key)` is called with the *current UI culture* (via `CultureInfo` stored in `StringResources.Culture`), not thread culture directly.
|
||||
- `StringResources` is auto-generated; manual edits to `StringResources.Designer.cs` will be overwritten.
|
||||
|
||||
---
|
||||
|
||||
### 4. Dependencies
|
||||
|
||||
#### Dependencies *of* `TranslateExtension`:
|
||||
- `System.Windows.Markup.MarkupExtension` (WPF base class)
|
||||
- `TestSetupsList.Resources.StringResources` (strongly-typed resource class)
|
||||
- Relies on `System.Resources.ResourceManager` and `System.Globalization.CultureInfo`
|
||||
- Requires the `StringResources.resx` file to be compiled into the `TestSetupsList` assembly (implied by `"TestSetupsList.Resources.StringResources"` in `ResourceManager` constructor).
|
||||
|
||||
#### Dependencies *on* `TranslateExtension`:
|
||||
- XAML files in the `TestSetupsList` module that use `{local:Translate KeyName}` syntax (where `local` maps to `TestSetupsList` namespace).
|
||||
- No direct runtime dependencies beyond WPF and the resource assembly.
|
||||
|
||||
---
|
||||
|
||||
### 5. Gotchas
|
||||
|
||||
- **No null-safety for missing keys**: A key like `"NonExistent"` yields `"#stringnotfound# NonExistent"` — not `null`, not an exception. This may cause visible artifacts in UI if not handled.
|
||||
- **Empty key handling**: Passing `""` or `null` to the constructor returns `"#stringnotfound#"` silently — no warning or exception.
|
||||
- **No caching of resolved values**: `ProvideValue` calls `ResourceManager.GetString(_key)` on *every invocation* (e.g., if used in a `DataTemplate` with many items). This is likely acceptable for typical UI strings but could be optimized.
|
||||
- **No support for format strings or parameters**: Unlike `String.Format`, this extension does *not* support placeholders (e.g., `"Hello {0}"`). Resource keys must resolve to fully formed strings.
|
||||
- **Designer.cs auto-generation warning**: Manual changes to `StringResources.Designer.cs` will be lost on rebuild. Resource keys must be added/modified via the `.resx` designer or file.
|
||||
- **No `serviceProvider` usage**: The `ProvideValue` method ignores the WPF-provided `IServiceProvider`, meaning it cannot resolve culture dynamically per context (e.g., per element). Relies solely on `StringResources.Culture`.
|
||||
|
||||
None identified beyond the above.
|
||||
Reference in New Issue
Block a user