Files
DP44/enriched-partialglm/DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/Resources.md
2026-04-17 14:55:32 -04:00

118 lines
6.8 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportSettings/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T11:00:37.156668+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "5a446a4aa0389800"
---
# Documentation: DTS.Viewer.PSDReportSettings.Resources
## 1. Purpose
This module provides localization/translation infrastructure for the PSD (Power Spectral Density) Report Settings UI within the DTS Viewer application. It consists of a WPF XAML markup extension (`TranslateExtension`) that enables declarative resource binding in XAML, and a strongly-typed auto-generated resource accessor class (`StringResources`) containing localized strings for filter configurations, window settings, envelope display options, and export functionality.
---
## 2. Public Interface
### `TranslateExtension` (class)
**Namespace:** `DTS.Viewer.PSDReportSettings`
**Inheritance:** `MarkupExtension`
**Attribute:** `[MarkupExtensionReturnType(typeof(string))]`
A WPF markup extension that resolves localization keys to localized strings at XAML parse time.
| 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 | `object ProvideValue(IServiceProvider serviceProvider)` | Returns the localized string for `_key` from `StringResources.ResourceManager`. Returns `#stringnotfound#` if `_key` is null or empty. Returns `#stringnotfound# <key>` if the key does not exist in the resource file. |
---
### `StringResources` (class)
**Namespace:** `DTS.Viewer.PSDReportSettings.Resources`
**Access:** `internal`
**Attribute:** `[GeneratedCode]`, `[DebuggerNonUserCode]`, `[CompilerGenerated]`
An auto-generated strongly-typed resource accessor class. **Not publicly accessible outside the assembly.**
| Member | Signature | Description |
|--------|-----------|-------------|
| Property | `static ResourceManager ResourceManager` | Lazily-initialized cached ResourceManager instance for the `DTS.Viewer.PSDReportSettings.Resources.StringResources` resource bundle. |
| Property | `static CultureInfo Culture` | Gets or sets the current UI culture for resource lookups. Overrides `Thread.CurrentUICulture` for this resource class. |
**Localized String Properties (all `internal static string`):**
| Property Name | Default Value (English) | Context |
|---------------|------------------------|---------|
| `EnvelopeHeader` | "Envelope" | UI header |
| `ExportPSDHeader` | "Export" | UI header |
| `ExportPSDtoCSV` | "Export PSD to CSV" | Export action |
| `ExportPSDtoPDF` | "Export PSD to PDF" | Export action |
| `FilterCenterFrequency` | "Center frequency" | Filter setting label |
| `FilterOrder` | "Filter order" | Filter setting label |
| `FilterSettingsHeader` | "Filters" | UI header |
| `FilterType` | "Filter type" | Filter setting label |
| `FilterType_Bessel` | "Bessel" | Filter type enum value |
| `FilterType_Butterworth` | "Butterworth" | Filter type enum value |
| `FilterType_LinkwitzRiley` | "Linkwitz-Riley" | Filter type enum value |
| `HighPassFilter` | "High pass filter" | Filter type |
| `Hz` | "Hz" | Unit label |
| `LowPassFilter` | "Low pass filter" | Filter type |
| `PSDSettingsHeader` | "PSD settings" | UI header |
| `ShowEnvelope` | "Show Envelope" | Checkbox/toggle label |
| `WindowAveragingType` | "Averaging type" | Window setting label |
| `WindowOverlappingPercent` | "Overlapping %" | Window setting label |
| `WindowSettingsHeader` | "Window" | UI header |
| `WindowType` | "Window type" | Window setting label |
| `WindowWidth` | "Window width" | Window setting label |
---
## 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 returns the constant `"#stringnotfound#"` for null/empty keys, or `"#stringnotfound# <key>"` for missing resource entries.
3. **ResourceManager singleton:** The `ResourceManager` property uses lazy initialization with a null-check pattern; once initialized, the same instance is returned for all subsequent calls.
4. **Thread-safety of ResourceManager:** The lazy initialization in `StringResources.ResourceManager` is **not thread-safe** (uses simple null check without locking). Concurrent access during first initialization could potentially create multiple ResourceManager instances.
5. **Internal visibility:** `StringResources` is marked `internal`, restricting access to within the `DTS.Viewer.PSDReportSettings` assembly.
---
## 4. Dependencies
### This module depends on:
- `System` (core types)
- `System.Windows.Markup` (`MarkupExtension`, `MarkupExtensionReturnTypeAttribute`)
- `System.Resources` (`ResourceManager`)
- `System.Globalization` (`CultureInfo`)
- `System.CodeDom.Compiler` (`GeneratedCodeAttribute`)
- `System.Diagnostics` (`DebuggerNonUserCodeAttribute`)
- `System.Runtime.CompilerServices` (`CompilerGeneratedAttribute`)
### External resource dependency:
- A `.resx` file (not shown in source) named `StringResources.resx` must exist in the `DTS.Viewer.PSDReportSettings.Resources` namespace to provide the actual localized values.
### What depends on this module:
- **Unclear from source alone.** The `TranslateExtension` is designed for XAML consumption within the PSD Report Settings UI, but the specific XAML files or controls using it are not present in the provided source.
---
## 5. Gotchas
1. **Auto-generated code warning:** `StringResources.Designer.cs` is tool-generated. Manual edits will be overwritten when the resource file is regenerated. The source explicitly warns: "Changes to this file may cause incorrect behavior and will be lost if the code is regenerated."
2. **Missing key visibility:** Missing localization keys result in visible error strings (`#stringnotfound#`) appearing in the UI rather than silent failures or exceptions. This is intentional for debugging but could leak into production if resource files are incomplete.
3. **Thread-safety gap:** The `ResourceManager` property getter performs a non-atomic check-then-assign pattern (`if (object.ReferenceEquals(resourceMan, null))`). Under concurrent access, multiple `ResourceManager` instances could be created, though the functional impact is likely minimal.
4. **Culture must be set explicitly:** The `StringResources.Culture` property allows overriding the current thread's UI culture, but it must be set manually. If never set, `resourceCulture` remains `null` and `ResourceManager.GetString` uses `Thread.CurrentUICulture`.
5. **No design-time validation:** The `TranslateExtension` constructor accepts any string key without validation. Typos in XAML will only manifest as `#stringnotfound#` at runtime.