WinUI3Localizer icon indicating copy to clipboard operation
WinUI3Localizer copied to clipboard

The property UseUidWhenLocalizedStringNotFound removed in the latest version

Open penndai opened this issue 9 months ago • 1 comments

Hi, after upgrading the WinUI3Localizer to the version - 2.2.0.0 from 1.0.1, we found the "UseUidWhenLocalizedStringNotFound" was removed, and the below calling will return empty string rather than the uid

Localizer.Get().GetLocalizedString(resourceKey)

Is there any other work around or way to keep the same behaviour as previous version?

penndai avatar Apr 03 '25 06:04 penndai

Hi @penndai !

I needed to make that change to be consistent with localization in XAML. Can you consider using a helper?

public static class LocalizerHelper
{
    public static string GetLocalizedStringEx(this ILocalizer localizer, string uid, bool returnUidOnEmptyString)
    {
        if (localizer.GetLocalizedString(uid) is string localizedString &&
            string.IsNullOrEmpty(localizedString) is false)
        {
            return localizedString;
        }

        if (returnUidOnEmptyString is true)
        {
            return uid;
        }

        return string.Empty;
    }
}
string localizedString = Localizer.Get().GetLocalizedStringEx(uid: "TEST_UID", returnUidOnEmptyString: true);

AndrewKeepCoding avatar Apr 03 '25 07:04 AndrewKeepCoding

Closing for now. Feel free to reopen or start a new issue if you need further assistance.

AndrewKeepCoding avatar Oct 21 '25 09:10 AndrewKeepCoding