5.3 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T14:01:03.783986+00:00 | zai-org/GLM-5-FP8 | 1 | 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:
- If
_keyis null or empty, returns the constant#stringnotfound#. - Otherwise, attempts to retrieve the string via
StringResources.ResourceManager.GetString(_key). - If the lookup returns null (key not found), returns
#stringnotfound#followed by the key name. - Returns the found string otherwise.
- If
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
ResourceManagerinstance 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
CultureInfoused for resource lookups. This overrides the current thread'sCurrentUICulturefor 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.ProvideValuealways returns astring(decorated by[MarkupExtensionReturnType(typeof(string))]). - Null Safety:
TranslateExtension.ProvideValuewill never return null. It guarantees a return value of either the localized string or a specific error constant (#stringnotfound#). - Resource Manager Singleton: The
StringResources.ResourceManagerproperty uses a lazy-initialization pattern to ensure only one instance ofResourceManagerexists for the class. - File Generation:
StringResources.Designer.csis auto-generated. Manual changes to this file will be overwritten if the associated.resxfile is modified and the project is rebuilt.
4. Dependencies
-
Internal Dependencies:
TranslateExtensiondepends directly onDTS.Viewer.Resources.StringResourcesto perform lookups viaStringResources.ResourceManager.
-
External Framework Dependencies:
System.Windows.Markup: Required forMarkupExtensionandMarkupExtensionReturnTypeAttribute(implies dependency on WPF/PresentationFramework assemblies).System.Resources: Required forResourceManager.System.Globalization: Required forCultureInfo.
5. Gotchas
- Typo in Resource String: The value for
SavePDFSuccesscontains 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.,
GraphsDefaultTitleis "Graphs " andTestsDefaultTitleis "Tests "). It is unclear if this is intentional formatting or data entry error. - Internal Visibility: The
StringResourcesclass is markedinternal. It is not accessible outside theDTS.Viewerassembly. - Silent Failure Mode:
TranslateExtensiondoes 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.csdirectly is unsafe; the correct workflow is to edit the.resxfile.