Files
2026-04-17 14:55:32 -04:00

117 lines
6.2 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestModification/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.TestModification/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T13:46:55.298377+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "46010437bced3eec"
---
# Documentation: DTS.Viewer.TestModification.Resources
## 1. Purpose
This module provides localization support for the DTS Viewer Test Modification feature. It enables XAML-based string resource lookup through a WPF markup extension (`TranslateExtension`) backed by a strongly-typed, auto-generated resource class (`StringResources`). The module centralizes all user-facing strings for the test modification UI, supporting potential internationalization and ensuring consistent string management.
---
## 2. Public Interface
### TranslateExtension (public class)
**Namespace:** `DTS.Viewer.TestModification`
**Base Class:** `System.Windows.Markup.MarkupExtension`
**Attribute:** `[MarkupExtensionReturnType(typeof(string))]`
A WPF markup extension that enables XAML bindings to localized string resources.
| Member | Signature | Description |
|--------|-----------|-------------|
| Constructor | `TranslateExtension(string key)` | Initializes the extension with the resource key to look up. The key is stored in a readonly field `_key`. |
| Method | `public override object ProvideValue(IServiceProvider serviceProvider)` | Returns the localized string for the provided key via `StringResources.ResourceManager.GetString(_key)`. Returns `#stringnotfound#` if key is null/empty, or `#stringnotfound# {key}` if the key is not found in resources. |
**Constants:**
- `private const string NotFound = "#stringnotfound#"` — Fallback value returned when a resource key is invalid or missing.
---
### StringResources (internal class)
**Namespace:** `DTS.Viewer.TestModification.Resources`
**Attributes:** `[GeneratedCode]`, `[DebuggerNonUserCode]`, `[CompilerGenerated]`
An auto-generated strongly-typed resource class. **Do not modify manually** — edits will be lost on regeneration.
| Member | Signature | Description |
|--------|-----------|-------------|
| Property | `internal static ResourceManager ResourceManager` | Returns the cached `ResourceManager` instance for the resource bundle `"DTS.Viewer.TestModification.Resources.StringResources"`. Lazily initialized. |
| Property | `internal static CultureInfo Culture` | Gets or sets the `CultureInfo` used for resource lookups. Overrides `CurrentUICulture` for this resource class. |
**Localized String Properties (all `internal static string`):**
| Property | Default Value (from comments) |
|----------|-------------------------------|
| `CalDate` | "Cal date" |
| `DataFlag` | "Data Flag:" |
| `Description` | "Description:" |
| `EUMultiplier` | "EU Multiplier:" |
| `EUOffset` | "EU Offset:" |
| `FailedToModifySensitivity` | "Failed to modify sensitivity: " |
| `Filter` | "Filter:" |
| `LineFit` | "Line Fit:" |
| `ModifyDate` | "Modify date" |
| `NonLinear` | "Non-linear" |
| `PleaseLockHeader` | "To enable, please lock a single channel." |
| `Preview` | "Preview" |
| `ProportionalToExcitation` | "Proportional to excitation" |
| `Sensitivity` | "Sensitivity:" |
| `SensorCalibration` | "Sensor calibration (most recent in db)" |
| `ShiftT0ms` | "Shift T₀ (ms):" |
| `T0MustBeInDataset` | "Modification can not be made, T0 must be in the dataset." |
| `T1ms` | "T₁ (ms):" |
| `T2ms` | "T₂ (ms):" |
| `Undo` | "Cancel" |
| `UndoAll` | "Restore All" |
| `UndoAllPrompt` | "This will revert your saved test modifications to the backup on file. Continue?" |
| `UndoPrompt` | "This will undo any change(s) to this channel made before saving. Continue?" |
| `UpdateDatabase` | "Update database" |
| `WriteFiles` | "Write" |
| `WriteFilesPrompt` | "Are you sure you want to write these changes to disk?" |
---
## 3. Invariants
1. **Key immutability:** The `_key` field in `TranslateExtension` is readonly and set only at construction time.
2. **Fallback behavior:** `ProvideValue` will never return null — it always returns either a valid localized string or a string containing `#stringnotfound#`.
3. **Error differentiation:** A null/empty key returns `"#stringnotfound#"` alone; a missing key returns `"#stringnotfound# {key}"` (includes the key name).
4. **Resource manager singleton:** `StringResources.ResourceManager` is lazily initialized and cached; subsequent accesses return the same instance.
5. **Auto-generated code:** `StringResources.Designer.cs` is regenerated by tooling; manual changes will be overwritten.
---
## 4. Dependencies
### This module depends on:
- `System` — Core .NET types
- `System.Windows.Markup``MarkupExtension` base class for XAML support
- `System.Resources``ResourceManager` for resource lookup
- `System.Globalization``CultureInfo` for localization
- `System.CodeDom.Compiler`, `System.Diagnostics`, `System.Runtime.CompilerServices` — Attributes for auto-generated code
### What depends on this module:
- XAML files in `DTS.Viewer.TestModification` that use the `{x:Static}` or `{local:Translate}` markup extension pattern for localized UI strings
- Code-behind in the TestModification module that accesses `StringResources` properties directly
---
## 5. Gotchas
1. **Different error formats:** A null/empty key returns `"#stringnotfound#"` without the key name, while a valid-but-missing key returns `"#stringnotfound# {key}"`. This could cause confusion when debugging missing resources.
2. **Auto-generated file:** `StringResources.Designer.cs` is tool-generated. To add or modify strings, edit the `.resx` file, not this file. The comments explicitly warn: "Changes to this file may cause incorrect behavior and will be lost if the code is regenerated."
3. **Internal visibility:** `StringResources` is `internal`, limiting access to within the assembly. `TranslateExtension` is `public`, making it usable from XAML regardless of assembly boundaries.
4. **Culture management:** The `Culture` property on `StringResources` allows overriding the lookup culture, but this is a global setting for the class. If set, it affects all subsequent resource lookups through this class. It is unclear from source alone whether/how the application manages this property at runtime.