Files
DP44/enriched-qwen3-coder-next/DataPRO/Modules/Database/DatabaseServices/Resources.md
2026-04-17 14:55:32 -04:00

52 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/Resources/TranslateExtension.cs
- DataPRO/Modules/Database/DatabaseServices/Resources/StringResources.Designer.cs
generated_at: "2026-04-16T04:35:33.501804+00:00"
model: "Qwen/Qwen3-Coder-Next-FP8"
schema_version: 1
sha256: "79b93425a9c97e71"
---
# Resources
## Documentation: `TranslateExtension` Markup Extension
### 1. Purpose
The `TranslateExtension` class is a WPF `MarkupExtension` that enables declarative localization of UI text directly in XAML. It resolves string resources by key at runtime using the `StringResources` strongly-typed resource class, returning localized strings or a standardized fallback for missing keys. This module exists to support multi-language UIs in the DatabaseServices module by abstracting resource lookup into a XAML-friendly syntax (e.g., `{local:Translate KeyName}`), decoupling UI text from code and enabling runtime culture switching.
### 2. Public Interface
- **`TranslateExtension(string key)`**
Constructor. Accepts a resource key (e.g., `"ClearingLocalDb"`) to look up. Throws no exceptions on invalid input—invalid keys are handled at lookup time.
- **`override object ProvideValue(IServiceProvider serviceProvider)`**
WPF framework method invoked during XAML parsing. Returns the localized string corresponding to `_key`, or a fallback value if the key is missing/empty.
- If `_key` is `null` or empty: returns `"#stringnotfound#"`.
- If `StringResources.ResourceManager.GetString(_key)` returns `null`: returns `"#stringnotfound# " + _key`.
- Otherwise: returns the localized string.
### 3. Invariants
- `_key` is immutable after construction (stored in a `readonly` field).
- The returned value is always a `string` (per `[MarkupExtensionReturnType(typeof(string))]`).
- No exceptions are thrown during `ProvideValue`—all error cases return a fallback string.
- Resource lookup uses the current UI culture (via `StringResources.Culture`), which may be set externally (e.g., by WPFs `FrameworkElement.Language` or manual assignment).
- The `StringResources` class is auto-generated and must be kept in sync with `.resx` files; changes to `.resx` require regeneration.
### 4. Dependencies
- **Depends on**:
- `System.Windows.Markup` (for `MarkupExtension` and `MarkupExtensionReturnType`).
- `DatabaseServices.Resources.StringResources` (strongly-typed resource class).
- `System.Resources.ResourceManager` (via `StringResources.ResourceManager`).
- **Used by**:
- XAML files in the `DatabaseServices` module (e.g., `Window.xaml`, `UserControl.xaml`) to bind localized text to UI elements.
- No direct programmatic callers in the provided source—usage is exclusively via XAML markup.
### 5. Gotchas
- **Hardcoded fallback prefix**: The `"#stringnotfound#"` string is hardcoded; changing it requires updating both `TranslateExtension` and any tests/scripts expecting this pattern.
- **No caching of lookups**: `ResourceManager.GetString(_key)` is called on every `ProvideValue` invocation. While `ResourceManager` caches internally, repeated lookups for the same key in high-frequency UI scenarios (e.g., data-bound lists) may incur overhead.
- **Silent failure on missing keys**: Missing keys produce visible text like `"#stringnotfound# ClearingLocalDb"` in the UI, which may confuse end users. No logging or telemetry is performed.
- **No null-safety for `serviceProvider`**: The `serviceProvider` parameter is unused, but if future changes require it (e.g., for service resolution), this could break.
- **Auto-generated resource class**: `StringResources.Designer.cs` is auto-generated—manual edits are unsafe and will be overwritten. Resource keys must match exactly (case-sensitive) with entries in the `.resx` file.
- **No support for pluralization/formatting**: The extension only supports simple key→string lookups; composite strings (e.g., `"Connected to: {0}"`) require manual formatting in code-behind or XAML.
None identified beyond these.