140 lines
6.9 KiB
Markdown
140 lines
6.9 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- DataPRO/Modules/Hardware/HardwareList/Resources/TranslateExtension.cs
|
||
|
|
- DataPRO/Modules/Hardware/HardwareList/Resources/StringResources.Designer.cs
|
||
|
|
generated_at: "2026-04-17T15:58:02.305916+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "044fd045b3bc16bb"
|
||
|
|
---
|
||
|
|
|
||
|
|
# Documentation: HardwareList Resources Module
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
|
||
|
|
This module provides localization/internationalization support for the HardwareList component of the DataPRO system. It enables XAML-based UI elements to declaratively reference localized strings through a markup extension pattern, while the underlying resource class provides strongly-typed access to hardware-related display text (device names, column headers, action labels, etc.). The module abstracts the resource lookup mechanism, allowing UI code to reference string resources by key without direct interaction with `ResourceManager`.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### `TranslateExtension` Class
|
||
|
|
**Namespace:** `HardwareList`
|
||
|
|
**Inheritance:** `System.Windows.Markup.MarkupExtension`
|
||
|
|
**Attribute:** `[MarkupExtensionReturnType(typeof(string))]`
|
||
|
|
|
||
|
|
| 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`. |
|
||
|
|
| `ProvideValue` | `override object ProvideValue(IServiceProvider serviceProvider)` | Returns the localized string for the stored key. Returns `#stringnotfound#` if key is null/empty, or `#stringnotfound# <key>` if the key is not found in resources. |
|
||
|
|
|
||
|
|
### `StringResources` Class
|
||
|
|
**Namespace:** `HardwareList.Resources`
|
||
|
|
**Accessibility:** `internal`
|
||
|
|
**Attribute:** Auto-generated by `StronglyTypedResourceBuilder`
|
||
|
|
|
||
|
|
| Member | Signature | Description |
|
||
|
|
|--------|-----------|-------------|
|
||
|
|
| `ResourceManager` | `static global::System.Resources.ResourceManager ResourceManager { get; }` | Returns the cached ResourceManager instance for the `HardwareList.Resources.StringResources` resource set. Lazily initialized on first access. |
|
||
|
|
| `Culture` | `static global::System.Globalization.CultureInfo Culture { get; set; }` | Gets or sets the culture used for resource lookups. Overrides `Thread.CurrentUICulture` for this resource class. |
|
||
|
|
|
||
|
|
**Static String Properties (selection):**
|
||
|
|
|
||
|
|
| Property | Default Value (English) |
|
||
|
|
|----------|------------------------|
|
||
|
|
| `Add` | "Add" |
|
||
|
|
| `Remove` | "Remove" |
|
||
|
|
| `Replace` | "Replace" |
|
||
|
|
| `Swap` | "Swap" |
|
||
|
|
| `SerialNumber` | "Serial Number" |
|
||
|
|
| `Firmware` | "Firmware" |
|
||
|
|
| `IPAddress` | "IP Address" |
|
||
|
|
| `Port` | "Port" |
|
||
|
|
| `HardwareType` | "Type" |
|
||
|
|
| `ChannelCount` | "Channels" |
|
||
|
|
| `MaxSampleRate` | "Max Sample Rate" |
|
||
|
|
| `TestSampleRate` | "Test Sample Rate" |
|
||
|
|
| `CalDate` | "Cal Date" |
|
||
|
|
| `CalDueDate` | "Cal Due Date" |
|
||
|
|
| `FirstUseDate` | "First Use Date" |
|
||
|
|
| `Connection` | "Connection" |
|
||
|
|
| `USB` | "USB" |
|
||
|
|
| `CAN` | "CAN" |
|
||
|
|
| `UART` | "UART" |
|
||
|
|
| `PositionOnChain` | "Position on chain" |
|
||
|
|
| `IsHWClockMaster` | "Clock Master?" |
|
||
|
|
| `PTPDomain` | "PTP Domain" |
|
||
|
|
| `NotFound` (constant in `TranslateExtension`) | `#stringnotfound#` |
|
||
|
|
|
||
|
|
**Hardware Device Name Properties (partial list):**
|
||
|
|
|
||
|
|
| Property | Default Value |
|
||
|
|
|----------|--------------|
|
||
|
|
| `SLICE_Base` | "SLICE" |
|
||
|
|
| `SLICE6_Base` | "SLICE 6" |
|
||
|
|
| `SLICE6_AIR` | "SLICE 6 AIR" |
|
||
|
|
| `SLICE2_Base` | "SLICE PRO SIM" |
|
||
|
|
| `SLICE2_DIM` | "SLICE PRO DIM" |
|
||
|
|
| `SLICE_IEPE` | "SLICE (IEPE)" |
|
||
|
|
| `SLICE_NANO_Base` | "SLICE (Nano)" |
|
||
|
|
| `SLICE_Micro_Base` | "SLICE (Micro)" |
|
||
|
|
| `SLICE1_5_Micro_Base` | "SLICE+" |
|
||
|
|
| `SLICE_Distributor` | "SLICE Distributor" |
|
||
|
|
| `SLICE_EthernetController` | "SLICE Ethernet Controller" |
|
||
|
|
| `TDAS_Pro_Rack` | "TDAS PRO Rack" |
|
||
|
|
| `TDAS_LabRack` | "TDAS PRO Lab Rack" |
|
||
|
|
| `G5VDS` | "G5 (VDS)" |
|
||
|
|
| `TSR_AIR` | "TSR AIR" |
|
||
|
|
| `Ribeye` | "Ribeye" |
|
||
|
|
| `PowerPro` | "PowerPRO Battery" |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
|
||
|
|
1. **Key Immutability:** The `_key` field in `TranslateExtension` is `readonly` and can only be set via the constructor.
|
||
|
|
|
||
|
|
2. **Error String Format:** Missing translations always follow the pattern:
|
||
|
|
- Null/empty key → `#stringnotfound#`
|
||
|
|
- Key not found → `#stringnotfound# <key>` (note the space before the key)
|
||
|
|
|
||
|
|
3. **Resource Manager Singleton:** The `ResourceManager` property uses lazy initialization with a null-check pattern; once initialized, the same instance is returned for all subsequent calls.
|
||
|
|
|
||
|
|
4. **Auto-generation Constraint:** `StringResources` is marked with `GeneratedCodeAttribute` and `CompilerGeneratedAttribute`. Manual edits will be overwritten when the `.resx` file is regenerated.
|
||
|
|
|
||
|
|
5. **Internal Visibility:** `StringResources` is `internal`, restricting access to within the defining assembly.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
|
||
|
|
### This Module Depends On:
|
||
|
|
- `System` (core types)
|
||
|
|
- `System.Windows.Markup` (`MarkupExtension` base class, `MarkupExtensionReturnTypeAttribute`)
|
||
|
|
- `System.Resources` (`ResourceManager` for resource lookup)
|
||
|
|
- `System.Globalization` (`CultureInfo` for culture-specific lookups)
|
||
|
|
- `System.CodeDom.Compiler` (attributes on generated code)
|
||
|
|
- `System.ComponentModel` (`EditorBrowsableAttribute`)
|
||
|
|
- `System.Diagnostics` (`DebuggerNonUserCodeAttribute`)
|
||
|
|
- `System.Runtime.CompilerServices` (`CompilerGeneratedAttribute`)
|
||
|
|
|
||
|
|
### External Resource Dependency:
|
||
|
|
- A `.resx` file named `StringResources.resx` (and culture-specific variants) must exist in the `HardwareList.Resources` namespace at compile time.
|
||
|
|
|
||
|
|
### What Depends On This Module:
|
||
|
|
- **Inferred:** Any XAML files in the `HardwareList` module that use `{local:Translate KeyName}` syntax for localized strings.
|
||
|
|
- **Inferred:** Code-behind files that reference `StringResources.<PropertyName>` directly.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
|
||
|
|
1. **Silent Failure Pattern:** `TranslateExtension.ProvideValue` never throws exceptions for missing keys. It returns error strings instead, which may appear directly in the UI. Consumers should test for the `#stringnotfound#` prefix if they need to detect missing translations programmatically.
|
||
|
|
|
||
|
|
2. **Culture Must Be Set Explicitly:** The `StringResources.Culture` property allows overriding the current thread's UI culture. If set, all subsequent lookups use this culture until reset. This can cause unexpected language switches if not managed carefully.
|
||
|
|
|
||
|
|
3. **Auto-generated File Warning:** The file header explicitly warns that changes to `StringResources.Designer.cs` will be lost on regeneration. Developers must edit the underlying `.resx` file instead.
|
||
|
|
|
||
|
|
4. **No Null Key Validation in Constructor:** `TranslateExtension` accepts null or empty keys without throwing; the validation only occurs in `ProvideValue()`. This means XAML with `{x:Null}` or empty string bindings will compile but produce `#stringnotfound#` at runtime.
|
||
|
|
|
||
|
|
5. **Inconsistent Device Naming:** Some device strings appear to have copy-paste errors in comments (e.g., `SLICE2_Bridge_Hi`, `SLICE2_Bridge_Lo`, `SLICE2_IEPE_Hi`, `SLICE2_IEPE_Lo` all have summary comments saying "SLICE PRO SIM" rather than their actual device type). This is documentation debt in the auto-generated file, not a runtime issue.
|