6.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T11:12:19.064013+00:00 | zai-org/GLM-5-FP8 | 1 | b58f3ee343f377b9 |
Documentation: DTS.Viewer.ViewerSettings.Resources
1. Purpose
This module provides localization infrastructure for the DTS Viewer settings UI. It consists of two components: TranslateExtension, a WPF MarkupExtension that enables XAML bindings to localized strings, and StringResources, an auto-generated strongly-typed resource class that wraps a .resx file containing the actual localized string values. Together, they allow XAML markup to reference localized strings declaratively (e.g., {local:Translate SomeKey}) while centralizing string management through the .NET resource system.
2. Public Interface
TranslateExtension (public class)
Namespace: DTS.Viewer.ViewerSettings
Base Class: 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. Stores the key in a readonly field _key. |
ProvideValue |
public override object ProvideValue(IServiceProvider serviceProvider) |
Returns the localized string for _key from StringResources.ResourceManager. Returns NotFound constant if _key is null or empty. Returns NotFound + " " + _key if the key is not found in resources. |
Constants:
private const string NotFound = "#stringnotfound#"— Fallback value returned when translation cannot be resolved.
StringResources (internal class)
Namespace: DTS.Viewer.ViewerSettings.Resources
Attributes: [GeneratedCode], [DebuggerNonUserCode], [CompilerGenerated]
| Member | Signature | Description |
|---|---|---|
ResourceManager |
internal static global::System.Resources.ResourceManager ResourceManager { get; } |
Lazily-initialized, cached ResourceManager instance for the DTS.Viewer.ViewerSettings.Resources.StringResources resource bundle. |
Culture |
internal static global::System.Globalization.CultureInfo Culture { get; set; } |
Overrides the current thread's CurrentUICulture for resource lookups via this class. Can be set to change localization at runtime. |
CalibrationBehavior_LinearIfAvailable |
internal static string CalibrationBehavior_LinearIfAvailable { get; } |
Localized string: "Use the linear sensitivity, if available." |
CalibrationBehavior_NonLinearIfAvailable |
internal static string CalibrationBehavior_NonLinearIfAvailable { get; } |
Localized string: "Use the non-linear sensitivity, if available." |
CalibrationBehavior_UseBothIfAvailable |
internal static string CalibrationBehavior_UseBothIfAvailable { get; } |
Localized string: "Use both sensitivities, if available, as separate channels." |
CalibrationBehaviorText |
internal static string CalibrationBehaviorText { get; } |
Localized string: "Calibration Behavior". |
3. Invariants
-
Key immutability:
_keyinTranslateExtensionis assigned once in the constructor and is readonly; it cannot be changed after instantiation. -
Non-null return guarantee:
TranslateExtension.ProvideValuealways returns a non-nullstring— either the localized value, theNotFoundconstant, orNotFound + " " + _key. -
ResourceManager singleton pattern:
StringResources.ResourceManageris lazily initialized on first access and cached; subsequent accesses return the same instance. -
Thread-safety of ResourceManager initialization: The getter checks for null using
object.ReferenceEquals(resourceMan, null)before creating a newResourceManager. Note: This pattern is not thread-safe; race conditions could result in multipleResourceManagerinstances being created. -
Resource key existence:
StringResourcesproperty getters passresourceCulture(which may be null) toResourceManager.GetString, defaulting to the current thread'sCurrentUICulturewhen null.
4. Dependencies
This module depends on:
System— Core .NET typesSystem.Windows.Markup—MarkupExtensionbase class andMarkupExtensionReturnTypeAttributeSystem.Resources—ResourceManagerfor resource lookupSystem.Globalization—CultureInfofor localizationSystem.CodeDom.Compiler,System.Diagnostics,System.Runtime.CompilerServices— Attributes for generated code (auto-generated dependency)- External resource file:
StringResources.resx(implied by the designer file; not included in source but required at runtime)
What depends on this module:
- Cannot be determined from source alone. The
TranslateExtensionis designed for XAML consumption within theDTS.Viewer.ViewerSettingsnamespace, but no consumers are shown in the provided files.
5. Gotchas
-
Different error formats for different failure modes: A null/empty key returns
"#stringnotfound#"alone, while a valid but missing key returns"#stringnotfound# {key}". This distinction can be used for debugging but may cause inconsistent UI display if not handled upstream. -
StringResources is internal: The class is marked
internal, so it cannot be accessed outside theDTS.Viewer.ViewerSettings.Resourcesnamespace's assembly.TranslateExtensionworks around this by accessingStringResources.ResourceManagerdirectly. -
Auto-generated file warning:
StringResources.Designer.csis tool-generated. Manual edits will be lost when the.resxfile is modified and the designer regenerates. The actual string values live inStringResources.resx, which is not included in the provided source. -
Thread-safety concern: The
ResourceManagerproperty getter uses a non-atomic null check pattern that is not thread-safe. In multi-threaded scenarios, two threads could simultaneously pass the null check and create separateResourceManagerinstances. While likely harmless in practice (the ResourceManager itself is thread-safe), this violates the singleton intent. -
Culture must be set explicitly on StringResources: Setting
Thread.CurrentUICulturewill NOT affectStringResourceslookups ifStringResources.Culturehas been explicitly set to a non-null value. Consumers must either leaveStringResources.Cultureas null (to inherit thread culture) or set it explicitly.