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

3.5 KiB
Raw Blame History

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/Modules/Menu/HamburgerMenu/Resources/TranslateExtension.cs
DataPRO/Modules/Menu/HamburgerMenu/Resources/StringResources.Designer.cs
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 the StringResources.resx file.
  • override object ProvideValue(IServiceProvider serviceProvider)
    Implements MarkupExtension.ProvideValue. Performs the resource lookup and returns the localized string or a placeholder.

    • Behavior:
      • If _key is null or 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").

3. Invariants

  • _key is immutable after construction (stored in a readonly field).
  • 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 on StringResources.Culture.

4. Dependencies

  • Depends on:
    • System.Windows.Markup.MarkupExtension (WPF framework)
    • HamburgerMenu.Resources.StringResources (strongly-typed resource class)
    • System.Resources.ResourceManager (via StringResources.ResourceManager)
  • Used by:
    • XAML files in the HamburgerMenu module (e.g., <TextBlock Text="{local:Translate Table_NA}" />).
    • No other C# code appears to depend on this class directly (it is XAML-only).

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.Culture being set appropriately (e.g., via Thread.CurrentThread.CurrentUICulture). If unset, the default culture is used.
  • Auto-generated resource class: StringResources.Designer.cs is auto-generated; edits will be overwritten. Resource keys must be managed via .resx files.
  • 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.