Skip to content

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

Open
@DexrnZacAttack

Description

@DexrnZacAttack

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions