84 lines
5.3 KiB
Markdown
84 lines
5.3 KiB
Markdown
|
|
---
|
||
|
|
source_files:
|
||
|
|
- DTS Viewer/DTS.Viewer/Resources/TranslateExtension.cs
|
||
|
|
- DTS Viewer/DTS.Viewer/Resources/StringResources.Designer.cs
|
||
|
|
generated_at: "2026-04-16T14:01:03.783986+00:00"
|
||
|
|
model: "zai-org/GLM-5-FP8"
|
||
|
|
schema_version: 1
|
||
|
|
sha256: "dbbc3094853fd65f"
|
||
|
|
---
|
||
|
|
|
||
|
|
# Documentation: DTS.Viewer Resources & Localization
|
||
|
|
|
||
|
|
## 1. Purpose
|
||
|
|
This module provides localization infrastructure for the DTS Viewer application. It bridges strongly-typed resource definitions (`StringResources`) with the XAML UI layer via a custom markup extension (`TranslateExtension`). The module allows XAML bindings to resolve string keys to localized values at runtime, falling back to error indicators when translations are missing, while the auto-generated `StringResources` class provides compile-time type safety for resource access within C# code.
|
||
|
|
|
||
|
|
## 2. Public Interface
|
||
|
|
|
||
|
|
### Class: `TranslateExtension`
|
||
|
|
**Namespace:** `DTS.Viewer`
|
||
|
|
**Inheritance:** `System.Windows.Markup.MarkupExtension`
|
||
|
|
|
||
|
|
This class is a XAML markup extension used to inject localized strings into the UI.
|
||
|
|
|
||
|
|
* **Constructor**
|
||
|
|
* `public TranslateExtension(string key)`
|
||
|
|
* Initializes a new instance of the extension with the specified resource key.
|
||
|
|
|
||
|
|
* **Method: ProvideValue**
|
||
|
|
* `public override object ProvideValue(IServiceProvider serviceProvider)`
|
||
|
|
* Resolves the resource key to a localized string.
|
||
|
|
* **Logic:**
|
||
|
|
1. If `_key` is null or empty, returns the constant `#stringnotfound#`.
|
||
|
|
2. Otherwise, attempts to retrieve the string via `StringResources.ResourceManager.GetString(_key)`.
|
||
|
|
3. If the lookup returns null (key not found), returns `#stringnotfound# ` followed by the key name.
|
||
|
|
4. Returns the found string otherwise.
|
||
|
|
|
||
|
|
### Class: `StringResources`
|
||
|
|
**Namespace:** `DTS.Viewer.Resources`
|
||
|
|
**Visibility:** `internal`
|
||
|
|
|
||
|
|
A strongly-typed resource class auto-generated by Visual Studio/ResGen. It provides access to localized strings defined in the corresponding `.resx` file.
|
||
|
|
|
||
|
|
* **Property: ResourceManager**
|
||
|
|
* `internal static global::System.Resources.ResourceManager ResourceManager`
|
||
|
|
* Returns the cached `ResourceManager` instance responsible for looking up resources. It is initialized with the base name `"DTS.Viewer.Resources.StringResources"`.
|
||
|
|
|
||
|
|
* **Property: Culture**
|
||
|
|
* `internal static global::System.Globalization.CultureInfo Culture`
|
||
|
|
* Gets or sets the current `CultureInfo` used for resource lookups. This overrides the current thread's `CurrentUICulture` for this resource class.
|
||
|
|
|
||
|
|
* **Static Resource Properties**
|
||
|
|
* `internal static string ChartOptionsHeader` (Value: "Chart Options")
|
||
|
|
* `internal static string GraphsDefaultTitle` (Value: "Graphs ")
|
||
|
|
* `internal static string ModificationsHeader` (Value: "Modify")
|
||
|
|
* `internal static string SavePDFError` (Value: "Error occurred saving chart to PDF")
|
||
|
|
* `internal static string SavePDFSuccess` (Value: "Chart saved succesfully as {0}{1} and {2}{3}")
|
||
|
|
* `internal static string SettingsTitle` (Value: "Settings")
|
||
|
|
* `internal static string TestIDsDefaultTitle` (Value: "Test IDs")
|
||
|
|
* `internal static string TestsDefaultTitle` (Value: "Tests ")
|
||
|
|
|
||
|
|
## 3. Invariants
|
||
|
|
|
||
|
|
* **Return Type Guarantee:** `TranslateExtension.ProvideValue` always returns a `string` (decorated by `[MarkupExtensionReturnType(typeof(string))]`).
|
||
|
|
* **Null Safety:** `TranslateExtension.ProvideValue` will never return null. It guarantees a return value of either the localized string or a specific error constant (`#stringnotfound#`).
|
||
|
|
* **Resource Manager Singleton:** The `StringResources.ResourceManager` property uses a lazy-initialization pattern to ensure only one instance of `ResourceManager` exists for the class.
|
||
|
|
* **File Generation:** `StringResources.Designer.cs` is auto-generated. Manual changes to this file will be overwritten if the associated `.resx` file is modified and the project is rebuilt.
|
||
|
|
|
||
|
|
## 4. Dependencies
|
||
|
|
|
||
|
|
* **Internal Dependencies:**
|
||
|
|
* `TranslateExtension` depends directly on `DTS.Viewer.Resources.StringResources` to perform lookups via `StringResources.ResourceManager`.
|
||
|
|
|
||
|
|
* **External Framework Dependencies:**
|
||
|
|
* `System.Windows.Markup`: Required for `MarkupExtension` and `MarkupExtensionReturnTypeAttribute` (implies dependency on WPF/PresentationFramework assemblies).
|
||
|
|
* `System.Resources`: Required for `ResourceManager`.
|
||
|
|
* `System.Globalization`: Required for `CultureInfo`.
|
||
|
|
|
||
|
|
## 5. Gotchas
|
||
|
|
|
||
|
|
* **Typo in Resource String:** The value for `SavePDFSuccess` contains a typo ("succesfully" instead of "successfully"). This exists in the source data and will appear in the UI.
|
||
|
|
* **Trailing Whitespace:** Several default resource values contain trailing spaces (e.g., `GraphsDefaultTitle` is "Graphs " and `TestsDefaultTitle` is "Tests "). It is unclear if this is intentional formatting or data entry error.
|
||
|
|
* **Internal Visibility:** The `StringResources` class is marked `internal`. It is not accessible outside the `DTS.Viewer` assembly.
|
||
|
|
* **Silent Failure Mode:** `TranslateExtension` does not log missing keys; it only visualizes them in the UI (e.g., `#stringnotfound# MissingKey`). Developers must visually inspect the UI to detect missing translations.
|
||
|
|
* **Designer File Modification:** As noted in the auto-generated header, modifying `StringResources.Designer.cs` directly is unsafe; the correct workflow is to edit the `.resx` file.
|