4.1 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:40:36.604143+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 4daa568e9b05fe61 |
Resources
Documentation: TranslateExtension Markup Extension
1. Purpose
This module provides a WPF MarkupExtension (TranslateExtension) to support localization of UI strings in XAML. It enables declarative binding of localized text resources (from StringResources) directly in XAML markup, using a string key. The extension acts as a bridge between the strongly-typed StringResources class and XAML, returning localized strings at runtime or a fallback marker when a key is missing or invalid.
2. Public Interface
TranslateExtension class
Namespace: DBImportExport.Resources
Inherits: MarkupExtension
-
Constructor
public TranslateExtension(string key)Initializes a new instance with the specified resource key. The key is stored in the private readonly field
_key. -
ProvideValuemethodpublic override object ProvideValue(IServiceProvider serviceProvider)Returns the localized string corresponding to
_key, or a fallback value if the key is null/empty or the string is not found.- If
_keyisnullor empty → returns"#stringnotfound#". - If
StringResources.ResourceManager.GetString(_key)returnsnull→ returns"#stringnotfound# " + _key. - Otherwise → returns the localized string.
- If
3. Invariants
_keyis immutable after construction (declaredreadonly).- The extension always returns a
string(per[MarkupExtensionReturnType(typeof(string))]). - If a resource key is missing or invalid, the return value is guaranteed to begin with
"#stringnotfound#"— no exceptions are thrown. - The
StringResources.ResourceManager.GetString(...)call is assumed to be thread-safe (standard forResourceManager), but no explicit synchronization is present inTranslateExtension.
4. Dependencies
Dependencies of this module:
System.Windows.Markup— forMarkupExtensionbase class andMarkupExtensionReturnTypeAttribute.DBImportExport.Resources.StringResources— specifically itsResourceManagerproperty and generated strongly-typed accessors (e.g.,ExportFileBrowse_Filter,ImportView_Browse, etc.).
Dependencies on this module:
- XAML files in the
DBImportExportmodule (e.g., views for Import/Export) likely use{local:Translate KeyName}syntax to bind localized strings to UI elements (e.g.,TextBlock.Text,Button.Content).
(Inferred from the presence ofStringResources.Designer.csand usage ofTranslateExtensionin aResourcesfolder.)
5. Gotchas
- No null-safety for
serviceProvider: TheProvideValuemethod does not validateserviceProvider— though WPF typically provides it, misuse outside WPF may cause issues. - Hardcoded fallback: The
"#stringnotfound#"prefix is hardcoded and not configurable. This may cause visual artifacts if not handled in UI design. - No caching of lookups: Each call to
ProvideValueperforms a freshResourceManager.GetString(...)lookup. WhileResourceManagercaches internally, repeated use in dynamic UIs (e.g., data templates) may incur minor overhead. - No culture switching support: The extension uses the current UI culture implicitly via
StringResources.Culture, but does not expose a way to override it per extension instance. - Auto-generated resource class:
StringResources.Designer.csis auto-generated — manual edits will be lost. Resource keys must match exactly (case-sensitive) with entries in the.resxfile. - No compile-time key validation: Passing an incorrect key (e.g.,
"ExportView_Browsse") will silently fall back to"#stringnotfound# ExportView_Browsse"at runtime.
None identified from source alone. (Note: The above are inferred based on common WPF localization patterns and the provided code structure.)