Files
DP44/enriched-qwen3-coder-next/DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportResults/Resources.md

73 lines
5.3 KiB
Markdown
Raw Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportResults/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Reports/DTS.Viewer.PSDReportResults/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T13:40:10.219585+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "154eee0c947eb6d0"
---
# Documentation: DTS.Viewer.PSDReportResults.Resources
## 1. Purpose
This module provides localization infrastructure for the PSD Report Results viewer within the DTS application. It bridges the gap between XAML UI definitions and localized string resources via a custom `TranslateExtension` markup extension. It allows developers to bind UI elements to resource keys declaratively, while relying on the auto-generated `StringResources` class to perform culture-aware string lookups for report-specific terminology such as "Channel Name," "Sample Rate," and export options.
## 2. Public Interface
### Class: `TranslateExtension`
**Namespace:** `DTS.Viewer.PSDReportResults`
**Inheritance:** `System.Windows.Markup.MarkupExtension`
This class is a XAML markup extension used to look up localized strings at runtime.
* **Constructor**
* `public TranslateExtension(string key)`: Initializes the extension with the resource key to be translated. The key is stored in a private readonly field `_key`.
* **Methods**
* `public override object ProvideValue(IServiceProvider serviceProvider)`: Returns the localized string corresponding to the `_key`.
* If `_key` is null or empty, it returns the constant `"#stringnotfound#"`.
* If the key is valid but no resource is found, it returns `"#stringnotfound# "` appended with the `_key`.
### Class: `StringResources`
**Namespace:** `DTS.Viewer.PSDReportResults.Resources`
**Accessibility:** `internal`
A strongly-typed resource class auto-generated by Visual Studio/ResGen. It provides access to localized strings defined in the corresponding `.resx` file.
* **Properties**
* `internal static global::System.Resources.ResourceManager ResourceManager`: Returns the cached `ResourceManager` instance responsible for looking up resources. The resource base name is `"DTS.Viewer.PSDReportResults.Resources.StringResources"`.
* `internal static global::System.Globalization.CultureInfo Culture`: Gets or sets the current `CultureInfo` used for resource lookups.
* `internal static string ChannelName`: Looks up a localized string (default: "Name").
* `internal static string ExportPSDHeader`: Looks up a localized string (default: "Export").
* `internal static string ExportPSDtoCSV`: Looks up a localized string (default: "Export PSD to CSV").
* `internal static string ExportPSDtoPDF`: Looks up a localized string (default: "Export PSD to PDF").
* `internal static string GRMS`: Looks up a localized string (default: "GRMS").
* `internal static string PSDResultsHeader`: Looks up a localized string (default: "Results").
* `internal static string SampleRate`: Looks up a localized string (default: "Sample Rate").
## 3. Invariants
1. **Return Type Guarantee:** The `TranslateExtension` class is decorated with `[MarkupExtensionReturnType(typeof(string))]`, guaranteeing that `ProvideValue` returns a `string` (despite the method signature returning `object`).
2. **Non-Null Return:** `TranslateExtension.ProvideValue` never returns null. It guarantees a string return, falling back to error indicators if the key is missing or empty.
3. **Resource Manager Singleton:** The `ResourceManager` property in `StringResources` implements a lazy-loading singleton pattern; it will only instantiate the `ResourceManager` once.
4. **Auto-Generated Constraint:** `StringResources` is marked with `DebuggerNonUserCodeAttribute` and `CompilerGeneratedAttribute`, indicating it should not be manually edited and must be regenerated when the `.resx` source changes.
## 4. Dependencies
* **Internal Dependencies:**
* `TranslateExtension` depends directly on `StringResources.ResourceManager` to perform lookups.
* **External Dependencies:**
* `System.Windows.Markup`: Required for `MarkupExtension` and `MarkupExtensionReturnTypeAttribute` (implies this is a WPF or related XAML-based UI project).
* `System.Resources`: Required for `ResourceManager`.
* `System.Globalization`: Required for `CultureInfo`.
* **Dependents:**
* XAML files within the `DTS.Viewer.PSDReportResults` assembly are the intended consumers of `TranslateExtension`.
## 5. Gotchas
1. **Differentiated Error States:** The `ProvideValue` method handles errors differently depending on the cause.
* A null/empty key returns exactly `"#stringnotfound#"`.
* A valid key that is missing from resources returns `"#stringnotfound# "` (note the trailing space) followed by the key name. Developers parsing logs or UI output should be aware of this format difference.
2. **Internal Visibility:** The `StringResources` class is `internal`. It cannot be accessed directly from outside the `DTS.Viewer.PSDReportResults` assembly. External assemblies must rely on the `TranslateExtension` (if public) or other public wrappers to access these strings.
3. **Hardcoded Fallback Strings:** The error strings `"#stringnotfound#"` are hardcoded in `TranslateExtension.cs`. They are not localized themselves (i.e., if the system language changes, these error messages remain in English/code-form).