Skip to content

Localization Resources Retrieved via IStringLocalizer Are Inconsistent with Those Obtained Through x:Uid #2821

Open
@MateralCMX

Description

@MateralCMX

Current behavior 🐛

/Strings/en/Resources.resw

  <data name="Account.PlaceholderText" xml:space="preserve">
    <value>Account</value>
  </data>

/Strings/zh/Resources.resw

  <data name="Account.PlaceholderText" xml:space="preserve">
    <value>帐号</value>
  </data>

CultureInfo is "zh"

Image

IStringLocalizer stringLocalizer = _serviceProvider.GetRequiredService();
string value = stringLocalizer["Account.PlaceholderText"].Value;

Image

Expected behavior 🎯

Localization resources retrieved using IStringLocalizer should be consistent with those obtained via x:Uid

How to reproduce it (as minimally and precisely as possible) 🔬

No response

Workaround 🛠️

Uno.Extensions.Localization.ResourceLoaderStringLocalizer

    private LocalizedString GetLocalizedString(string name, params object[] arguments)
    {
……
#if WINDOWS
            ResourceManager resourceManager = new();
            ResourceContext resourceContext = resourceManager.CreateResourceContext();
            resourceContext.QualifierValues["Language"] = CultureInfo.CurrentCulture.Name;
            resource = _appResourceMap.GetValue(name, resourceContext)?.ValueAsString ??
                _defaultResourceMap.GetValue(name, resourceContext)?.ValueAsString;
#else
                resource =(_appResourceLoader?.GetString(name) is { Length: > 0 } tmp ? tmp : null) ??
                _defaultResourceLoader.GetString(name);
#endif
……
    }

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

Windows App SDK

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't workingtriage/untriagedIndicates an issue requires triaging or verification.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions