oqtane/oqtane.framework

[ENH] Get language information Sync - or place it in the PageState / SiteState

Closed this issue · 5 comments

Oqtane Info

Version - 6 and all previous

Describe the enhancement

I'm working on a library called cre8magic which should make theme creation much easier. It's about 80% done and almost everything is straight forward, except for the Language Menu component I'm building.

Reason is that getting the languages is just about the only page/site information which must be retrieved async.
I believe I have to use ILanguageService.GetLanguagesAsync(siteId).

My understanding is that this information cannot really change, and is probably used in various places to get everything right.
So my request is to make sure that there is either a sync-variant of this call,
or better still, just put it on SiteState or PageState. I think I would prefer SiteState TBH.

Can you please provide additional clarification on what you are trying to accomplish. In general, you should NEVER make synchronous calls from within Blazor components to retrieve data - it should always be done asynchronously. This is why the entire API in Oqtane in asynchronous. Even the various "state" objects are loaded asynchronously and then passed down the component render tree (where their values are available as standard properties).

Also PageState already has a Languages property

I'm creating a switch-language menu which has more options / customizations etc.

To get the list of available languages, ATM I only see the async command.

So I believe the PageState only has the current language, but not the possible languages (which should probably be on the SiteState.

If you are creating a menu then it sounds like you are creating a UI component. UI components should only use asynchronous methods for loading data.

You are correct that the LanguageService (as well as every other Service in the Oqtane API) only provides asynchronous methods. We will not be introducing synchronous methods.

PageState contains the following property:

        public List<Language> Languages
        {
            get { return Site?.Languages; }
        }

If you look at the existing Language menu (Oqtane.Client\Themes\Controls\Theme\LanguageSwitcher.razor) you will see that it uses PageState.Languages to obtain the list of languages for the site.

I will close this issue as the functionality you are requesting already exists.

This is great!

Thanks a bunch.

I had been recycling some older code which was based on Oqtane where this property probably didn't exist yet.
My bad, thanks!