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

145 lines
7.4 KiB
Markdown

---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T13:58:32.085292+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "5726c0d4d71935f1"
---
# Documentation: DTS.Viewer.AddCalculatedChannel.Resources
## 1. Purpose
This module provides localization infrastructure for the "Add Calculated Channel" feature within the DTS Viewer application. It enables XAML-based UI elements to bind to localized strings at design-time and runtime through a WPF markup extension pattern, while the `StringResources` class serves as a strongly-typed accessor for culture-specific strings related to calculation types, channel operations, IR-TRACC measurements, and validation error messages.
---
## 2. Public Interface
### TranslateExtension (MarkupExtension)
**Class Definition:**
```csharp
[MarkupExtensionReturnType(typeof(string))]
public class TranslateExtension : MarkupExtension
```
**Constructor:**
```csharp
public TranslateExtension(string key)
```
Initializes the extension with a resource key to look up.
**Method:**
```csharp
public override object ProvideValue(IServiceProvider serviceProvider)
```
Returns the localized string for the provided `_key`. Returns `#stringnotfound#` if `_key` is null or empty. Returns `#stringnotfound# <key>` (where `<key>` is the actual key value) if the resource manager returns null for the given key.
---
### StringResources (Auto-generated Resource Class)
**Class Definition:**
```csharp
internal class StringResources
```
**Properties:**
| Property | Type | Description |
|----------|------|-------------|
| `ResourceManager` | `global::System.Resources.ResourceManager` (static) | Cached ResourceManager instance for the `DTS.Viewer.AddCalculatedChannel.Resources.StringResources` resource bundle |
| `Culture` | `global::System.Globalization.CultureInfo` (static) | Gets or sets the current thread's CurrentUICulture for resource lookups |
**Resource String Properties (static, read-only):**
| Property Name | Default Value (from comments) |
|---------------|-------------------------------|
| `AddCalculatedChannel` | "Add Calculated Channel" |
| `CalculatedChannel_Average` | "Average" |
| `CalculatedChannel_Sum` | "Sum" |
| `CalculatedChannel_IRTRACC3D` | "3D IR-TRACC (upper thorax)" |
| `CalculatedChannel_IRTRACC3D_Abdomen` | "3D IR-TRACC (abdomen)" |
| `CalculatedChannel_IRTRACC3D_LowerThorax` | "3D IR-TRACC (lower thorax)" |
| `CalculatedChannel_IRTRACC3D_Thorax` | "3D IR-TRACC (thorax)" |
| `CalculatedChannel_IRTRACC3DAbdomen` | "3D IR-TRACC (abdomen)" |
| `CalculatedChannel_IRTRACC3DLowerThorax` | "3D IR-TRACC (lower thorax)" |
| `Calculation` | "Calculation" |
| `CALCULATION_Cos` | "Cosine" |
| `CALCULATION_Derivative` | "Derivative" |
| `CALCULATION_DoubleIntegral` | "Double integral" |
| `CALCULATION_Integral` | "Integral" |
| `CALCULATION_Sin` | "Sine" |
| `CALCULATION_ThreeDIRTracc` | "3D IR-TRACC (upper thorax)" |
| `CALCULATION_ThreeDIRTraccAbdomen` | "3D IR-TRACC (abdomen)" |
| `CALCULATION_ThreeDIRTraccLowerThorax` | "3D IR-TRACC (lower thorax)" |
| `CalculationInputChannel` | "Calculation Input Channel" |
| `Channel` | "Channel" |
| `ChannelName` | "Channel Name" |
| `ClipLengthMS` | "Clip length (ms)" |
| `Description` | "Description" |
| `HICAccelerationX` | "Acceleration X" |
| `HICAccelerationY` | "Acceleration Y" |
| `HICAccelerationZ` | "AccelerationZ" |
| `HICRequires3Channels` | "Error: Head injury criterion requires 3 channels." |
| `InputChannels` | "Input channels" |
| `ISOCode` | "ISO Code" |
| `NoChannelsIncluded` | "Error: No channels included." |
| `ResultantUnitsDontMatch` | "Error: Units don't match for all input channels." |
| `SampleRatesDontMatch` | "Error: Sample rates don't match for all input channels." |
| `SuperSamplingWarning` | "Calculation contains multiple sample rates. Input will be resampled to the highest sample rate using linear interpolation." |
| `ThreeD_IRTracc` | "IR-TRACC" |
| `ThreeD_RotPot1` | "R. Pot Y" |
| `ThreeD_RotPot2` | "R. Pot Z" |
---
## 3. Invariants
- **TranslateExtension return guarantee:** `ProvideValue` always returns a non-null `string` object; it never returns null.
- **Error indicator format:** Missing keys are indicated by the constant `#stringnotfound#` (exact literal, lowercase), optionally followed by a space and the key name.
- **StringResources visibility:** The `StringResources` class is `internal` and only accessible within the `DTS.Viewer.AddCalculatedChannel` assembly.
- **Auto-generation constraint:** `StringResources.Designer.cs` is auto-generated by `System.Resources.Tools.StronglyTypedResourceBuilder` (version 17.0.0.0). Manual edits will be lost upon regeneration.
- **Resource bundle path:** Resources are loaded from the manifest resource name `"DTS.Viewer.AddCalculatedChannel.Resources.StringResources"`.
---
## 4. Dependencies
### This module depends on:
- `System` (core types)
- `System.Windows.Markup` (for `MarkupExtension` and `MarkupExtensionReturnTypeAttribute`)
- `System.Resources` (for `ResourceManager`)
- `System.Globalization` (for `CultureInfo`)
- `System.CodeDom.Compiler`, `System.Diagnostics`, `System.Runtime.CompilerServices`, `System.ComponentModel`, `System.Diagnostics.CodeAnalysis` (for auto-generated attributes)
### What depends on this module:
- **Inferred:** XAML files within the `DTS.Viewer.AddCalculatedChannel` namespace that use the `{local:Translate KeyName}` markup extension syntax for localized UI strings.
- **Inferred:** Code-behind files that reference `StringResources.<PropertyName>` for error messages and labels.
---
## 5. Gotchas
1. **Duplicate/near-duplicate resource keys:** Several IR-TRACC-related strings exist with different naming conventions that produce identical default values:
- `CalculatedChannel_IRTRACC3D_Abdomen` and `CalculatedChannel_IRTRACC3DAbdomen` both default to "3D IR-TRACC (abdomen)"
- `CalculatedChannel_IRTRACC3D_LowerThorax` and `CalculatedChannel_IRTRACC3DLowerThorax` both default to "3D IR-TRACC (lower thorax)"
- `CALCULATION_ThreeDIRTracc` and `CalculatedChannel_IRTRACC3D` both default to "3D IR-TRACC (upper thorax)"
This may indicate a naming convention migration or accidental duplication. The source alone does not clarify which keys are actively used.
2. **Inconsistent key naming conventions:** Resource keys use at least three different naming patterns:
- `PascalCase` (e.g., `Channel`, `Description`)
- `Category_Property` (e.g., `CalculatedChannel_Average`)
- `CATEGORY_Property` (e.g., `CALCULATION_Sin`, `CALCULATION_Derivative`)
Developers adding new keys should verify which convention is expected.
3. **Typo in HICAccelerationZ:** The default value is "AccelerationZ" (no space), whereas `HICAccelerationX` and `HICAccelerationY` have spaces ("Acceleration X", "Acceleration Y"). This inconsistency is visible in the source comments.
4. **NotFound constant is private:** The `NotFound` constant in `TranslateExtension` is `private const string`, so consumers cannot reference it for comparison. The literal `#stringnotfound#` would need to be hardcoded for string comparison checks.
5. **No null-coalescing on empty string:** `ProvideValue` checks `string.IsNullOrEmpty(_key)`, returning `NotFound` without appending the key. However, if `_key` is an empty string, the caller receives `#stringnotfound#` without indication that an empty string was passed.