4.9 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:45:43.131858+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | d8e7eb58224237bd |
Resources
Documentation: TranslateExtension Markup Extension
1. Purpose
This module provides a WPF MarkupExtension (TranslateExtension) to enable declarative, localized string resolution in XAML. It allows UI elements to bind to localized resources using a string key, falling back to a visible placeholder if the key is missing or the resource is unavailable. Its role is to support internationalization (i18n) of the Group Import module’s UI by abstracting resource lookup away from code-behind and into XAML markup.
2. Public Interface
TranslateExtension class
Namespace: DBImportExport.Resources
Base class: System.Windows.Markup.MarkupExtension
Attribute: [MarkupExtensionReturnType(typeof(string))]
Constructor
public TranslateExtension(string key)
- Parameters:
key: The resource key (e.g.,"GroupTags","Import_Importing") used to look up a localized string inStringResources.
- Behavior: Stores the key for later use in
ProvideValue.
ProvideValue method
public override object ProvideValue(IServiceProvider serviceProvider)
- Returns:
string - Behavior:
- If
_keyisnullor empty → returns"#stringnotfound#". - Otherwise, attempts to retrieve the string via
StringResources.ResourceManager.GetString(_key).- If found → returns the localized string.
- If not found (
null) → returns"#stringnotfound# " + _key(e.g.,"#stringnotfound# Import_Importing").
- If
- Note: The
serviceProviderparameter is unused.
3. Invariants
_keyis immutable after construction (no setter, no mutation).StringResources.ResourceManager.GetString(key)is the only source of localized strings; no fallback logic beyond theNotFoundconstant is implemented.- The
NotFoundconstant ("#stringnotfound#") is used consistently for both missing keys and missing values. - If
StringResources.ResourceManagerfails to initialize (e.g., due to assembly/resource loading issues),GetStringmay throw — but this is not handled in the extension and would result in a runtime exception.
4. Dependencies
Internal Dependencies
GroupImport.Resources.StringResources:- Strongly-typed resource class generated from
.resxfiles. - Provides access to localized strings via
ResourceManager.GetString(key). - Contains keys like
"GroupTags","Import_Importing","Preview_InvalidName", etc.
- Strongly-typed resource class generated from
External Dependencies
System.Windows.Markup.MarkupExtension: Base class for WPF markup extensions.System: Used forstring.IsNullOrEmpty,object.ReferenceEquals, etc.
Consumers (Inferred)
- XAML files in the
GroupImportmodule (e.g.,*.xaml) that use{local:Translate KeyName}syntax to bind UI text to localized resources.
5. Gotchas
- No null-safety for
ResourceManager.GetString(): IfStringResources.ResourceManageris misconfigured (e.g., wrong base name"GroupImport.Resources.StringResources"),GetStringmay returnnullor throw — the extension only handlesnullby appending the key to#stringnotfound#. - Hardcoded
NotFoundstring: The placeholder"#stringnotfound#"is visible in the UI if a key is missing, which may confuse end users. No localization-aware fallback (e.g., returning the key itself) is implemented. - No caching of resolved values:
ProvideValueis called repeatedly (e.g., during layout updates), and each call re-invokesResourceManager.GetString. WhileResourceManagercaches internally, repeated calls are still inefficient. - Namespace mismatch: The class resides in
DBImportExport.Resourcesbut referencesGroupImport.Resources.StringResources. This may indicate legacy refactoring or intentional decoupling — developers should verify assembly/resource naming consistency. - No support for format strings: While
StringResourcescontains format strings (e.g.,"Importing {0}:{1}"),TranslateExtensiondoes not accept or apply arguments — it only resolves the raw key. Formatting must be handled elsewhere (e.g., in code-behind or viaString.Formatafter resolution). - Auto-generated
StringResources.Designer.cs: Changes to.resxfiles require regeneration ofStringResources. If keys are renamed/removed in.resxbut not updated in XAML,TranslateExtensionwill return the#stringnotfound#fallback.
None identified from source alone regarding thread-safety, disposal, or WPF-specific lifecycle quirks — but given the simplicity of the extension, it is likely safe for standard WPF usage.