3.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T04:48:26.109962+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 846fd5844632234a |
Resources
Documentation: TranslateExtension Class
1. Purpose
The TranslateExtension class is a WPF MarkupExtension that enables declarative localization of UI strings in XAML. It resolves a given resource key at runtime by querying the StringResources strongly-typed resource class and returns the corresponding localized string. If the key is missing or the lookup fails, it returns a placeholder string to make missing translations visually obvious during development. This module exists to support multi-language UIs in the HamburgerMenu module without requiring code-behind for simple string bindings.
2. Public Interface
-
TranslateExtension(string key)
Constructor. Accepts a non-null resource key string used to look up a localized value.- Parameter:
key(string) – The resource key (e.g.,"Table_NA"). Must match a key in theStringResources.resxfile.
- Parameter:
-
override object ProvideValue(IServiceProvider serviceProvider)
ImplementsMarkupExtension.ProvideValue. Performs the resource lookup and returns the localized string or a placeholder.- Behavior:
- If
_keyisnullor empty → returns"#stringnotfound#". - Else → attempts
StringResources.ResourceManager.GetString(_key).- If found → returns the string.
- If not found (
null) → returns"#stringnotfound# " + _key(e.g.,"#stringnotfound# MyKey").
- If
- Behavior:
3. Invariants
_keyis immutable after construction (stored in areadonlyfield).- The returned value is always a
string(per[MarkupExtensionReturnType(typeof(string))]). - Missing keys are never silently ignored; they always produce a visible placeholder string.
- Resource lookup uses the current UI culture (
CultureInfo) set onStringResources.Culture.
4. Dependencies
- Depends on:
System.Windows.Markup.MarkupExtension(WPF framework)HamburgerMenu.Resources.StringResources(strongly-typed resource class)System.Resources.ResourceManager(viaStringResources.ResourceManager)
- Used by:
- XAML files in the
HamburgerMenumodule (e.g.,<TextBlock Text="{local:Translate Table_NA}" />). - No other C# code appears to depend on this class directly (it is XAML-only).
- XAML files in the
5. Gotchas
- Hardcoded placeholder: The
"#stringnotfound#"prefix is hardcoded; changing it requires modifying this class. - No fallback chain: If a key is missing, no secondary key or default value is attempted—only the placeholder is returned.
- No compile-time key validation: Typos in XAML (e.g.,
{local:Translate Tabl_NA}) will only surface at runtime as"#stringnotfound# Tabl_NA". - Culture dependency: Localization behavior relies on
StringResources.Culturebeing set appropriately (e.g., viaThread.CurrentThread.CurrentUICulture). If unset, the default culture is used. - Auto-generated resource class:
StringResources.Designer.csis auto-generated; edits will be overwritten. Resource keys must be managed via.resxfiles. - No async/safe fallback:
GetString()is synchronous and may throw if the underlying resource stream is corrupted (though this is rare).
None identified beyond the above.