WinUI3Localizer icon indicating copy to clipboard operation
WinUI3Localizer copied to clipboard

Issues getting strings that are clearly there (even seen in a breakpoint)

Open DexrnZacAttack opened this issue 9 months ago • 3 comments

My setup looks a bit like this: Strings/en-US/Resources.resw

under app.xaml.cs:

        private static async Task InitializeLocalizer()
        {
            string StringsFolderPath = Path.Combine(AppContext.BaseDirectory, "Strings");
            StorageFolder stringsFolder = await StorageFolder.GetFolderFromPathAsync(StringsFolderPath);

            ILocalizer localizer = await new LocalizerBuilder()
                .AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath)
                .SetOptions(options =>
                {
                    options.DefaultLanguage = "en-US";
                })
                .Build();
            Logger.WriteDebug($"Using language {localizer.GetCurrentLanguage()}");
        }

        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            await InitializeLocalizer();
            Logger.WriteDebug("Showing MainWindow");
            MainWindow.Activate();
        }

There's a helper that I often call, which does this:

        public static string GetLocalizedText(string name, params object[] args)
        {
            String translated = Localizer.Get().GetLocalizedString(name);
            if (translated == "")
                Logger.Write(LogLevel.Warning, $"String {name} not found in string resources.");
            return string.Format(translated == "" ? $"LOCALIZATION ERROR: String {name} not found in string resources." : translated, args);
        }

When stepping through the application, I can actually see the strings under the ILocalizer, but it always returns String.Empty in the end. The app is unpackaged, and I'm not sure if this is enough information so please lmk if you need more.

DexrnZacAttack avatar Jan 13 '25 04:01 DexrnZacAttack