84 lines
5.1 KiB
Markdown
84 lines
5.1 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.ChartOptions/Resources/TranslateExtension.cs
|
||
|
|
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.ChartOptions/Resources/StringResources.Designer.cs
|
||
|
|
generated_at: "2026-04-16T13:56:16.461808+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "8d340ea94a701586"
|
||
|
|
---
|
||
|
|
|
||
|
|
# Documentation: DTS.Viewer.ChartOptions Resources
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
This module provides localization infrastructure for the `DTS.Viewer.ChartOptions` namespace. It consists of a strongly-typed resource accessor class (`StringResources`) generated from a `.resx` file, and a XAML markup extension (`TranslateExtension`) that allows UI elements to bind directly to localized strings. This separates user-facing string management from application logic, supporting multi-language scenarios.
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### `TranslateExtension` (Class)
|
||
|
|
**Namespace:** `DTS.Viewer.ChartOptions`
|
||
|
|
**Inheritance:** `System.Windows.Markup.MarkupExtension`
|
||
|
|
|
||
|
|
This class enables XAML binding to localized resources.
|
||
|
|
|
||
|
|
* **Constructor**
|
||
|
|
* `public TranslateExtension(string key)`: Initializes the extension with the resource key to look up.
|
||
|
|
|
||
|
|
* **Methods**
|
||
|
|
* `public override object ProvideValue(IServiceProvider serviceProvider)`: Resolves the `_key` provided in the constructor to a localized string.
|
||
|
|
* Returns the localized string if found.
|
||
|
|
* Returns `#stringnotfound#` if the key is null or empty.
|
||
|
|
* Returns `#stringnotfound# [key]` if the lookup fails for a specific key.
|
||
|
|
|
||
|
|
### `StringResources` (Class)
|
||
|
|
**Namespace:** `DTS.Viewer.ChartOptions.Resources`
|
||
|
|
**Access Modifier:** `internal`
|
||
|
|
|
||
|
|
A strongly-typed resource class auto-generated by Visual Studio. It provides static properties to access culture-specific string values.
|
||
|
|
|
||
|
|
* **Properties**
|
||
|
|
* `internal static global::System.Resources.ResourceManager ResourceManager`: Gets the cached `ResourceManager` instance for this assembly.
|
||
|
|
* `internal static global::System.Globalization.CultureInfo Culture`: Gets or sets the current UI culture used for resource lookups.
|
||
|
|
|
||
|
|
* **Resource String Properties (Static, Read-Only)**
|
||
|
|
The following properties return localized strings corresponding to specific UI elements:
|
||
|
|
* `ChartUnitType`
|
||
|
|
* `FilterOptions_Title`
|
||
|
|
* `LockT`
|
||
|
|
* `MaxT`
|
||
|
|
* `MaxY`
|
||
|
|
* `MinT`
|
||
|
|
* `MinY`
|
||
|
|
* `Range`
|
||
|
|
* `ResetAll`
|
||
|
|
* `ResetT`
|
||
|
|
* `SaveChart`
|
||
|
|
* `SaveToPDF`
|
||
|
|
* `TimeUnitType`
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
|
||
|
|
1. **Return Type Guarantee:** The `TranslateExtension` class is decorated with `[MarkupExtensionReturnType(typeof(string))]`, guaranteeing that `ProvideValue` returns a `string` (boxed as `object`).
|
||
|
|
2. **Non-Null Return:** `TranslateExtension.ProvideValue` will never return `null`. It guarantees a return value even if the key is missing or invalid (returning a fallback error string).
|
||
|
|
3. **Resource Manager Singleton:** `StringResources.ResourceManager` uses a lazy-initialization pattern; it creates the `ResourceManager` instance only once and caches it in the private static field `resourceMan`.
|
||
|
|
4. **Immutability of Key:** Once `TranslateExtension` is constructed, the `_key` field is `readonly` and cannot be changed.
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
|
||
|
|
**Internal Dependencies:**
|
||
|
|
* `TranslateExtension` depends entirely on `StringResources.ResourceManager` to perform the actual string lookup.
|
||
|
|
|
||
|
|
**External Dependencies:**
|
||
|
|
* `System.Windows.Markup`: Required for `MarkupExtension` and `IServiceProvider` (implies this is a WPF module).
|
||
|
|
* `System.Resources`: Required for `ResourceManager`.
|
||
|
|
* `System.Globalization`: Required for `CultureInfo`.
|
||
|
|
|
||
|
|
**Downstream Dependencies:**
|
||
|
|
* XAML files within the `DTS.Viewer.ChartOptions` module (or other modules referencing this namespace) depend on `TranslateExtension` to display localized text (e.g., usage likely looks like `{local:Translate KeyName}`).
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
|
||
|
|
1. **Silent Failure Behavior:** `TranslateExtension` does not throw exceptions for missing keys. Instead, it returns the literal string `#stringnotfound#` (for null/empty keys) or `#stringnotfound# [key]` (for missing keys). This visual indicator might appear in the UI if resources are misconfigured, rather than causing a compile-time or runtime crash.
|
||
|
|
2. **Auto-Generated Code:** `StringResources` is marked with `GeneratedCodeAttribute`. Manual edits to this file will be overwritten if the resource tooling regenerates it. The actual string values reside in an external `.resx` file (likely `StringResources.resx`) which is not visible in the provided source but is implied by the designer file.
|
||
|
|
3. **Internal Visibility:** The `StringResources` class is `internal`. It cannot be accessed directly from outside the `DTS.Viewer.ChartOptions` assembly. However, `TranslateExtension` is `public`, allowing external assemblies to use the XAML extension if they reference this assembly.
|
||
|
|
4. **Case Sensitivity:** The `ResourceManager.GetString` method called by `TranslateExtension` is typically case-sensitive regarding the resource key (depending on the underlying resource set implementation), though the constant `_key` is passed exactly as provided to the constructor.
|