AndrewKeepCoding/WinUI3Localizer

MVVM Pattern

Closed this issue · 4 comments

how we can use this lib in mvvm pattern?

I guess you can't. Do you have any specific use cases?

I guess you can't. Do you have any specific use cases?

No, but it is useful to have it.
i think we can add service first:

.AddSingleton<ILocalizer, Localizer>()
then in MainViewModel we can initialize:

public MainViewModel(ILocalizer localizer)
{
localizer.AddStringResourcesFolderForLanguageDictionaries(StringsFolderPath);
}

I didn't test, I don't know if it works or not

.AddSingleton<ILocalizer, Localizer>()

The code above won't work. The Localizer is designed to be created only by the LocalizerBuilder. Once it's created you can use it in dependency injection:

.AddSingleton<ILocalizer>(_ => Localizer.Get())

Anyway, once is initialized, you can't add dictionaries.

Closing this as not planed.