AlexTeixeira / Askmethat-Aspnet-JsonLocalizer

Json Localizer library for .NetStandard and .NetCore Asp.net projects
MIT License
91 stars 29 forks source link

Getting error message JsonFileList is required in Client WASM mode #130

Open JerseyTechGuy opened 2 years ago

JerseyTechGuy commented 2 years ago

I have a Blazor App already using localization. It is a Wasm app with an API backend. I already had both French and English resx files in the Resources folder. Was configured in the Program.cs as follows. builder.Services.AddLocalization(options => options.ResourcesPath = "Resources")

I created a new json file called localization in the Resources folder. Added the following to the program.cs in place of the above code.

            builder.Services.AddJsonLocalization(options => {
                options.CacheDuration = TimeSpan.FromMinutes(60);
                options.ResourcesPath = "Resources";
                options.SupportedCultureInfos = new HashSet<CultureInfo>()
                {
                    new CultureInfo(GlobalConstants.Localization.Culture.US_English),
                    new CultureInfo(GlobalConstants.Localization.Culture.CA_French)
                };
            });

The error I am getting is JsonFileList is required in Client WASM mode. I assume this is because it is not finding any json files? Any help you could provide diagnosing would be appreciated. I did check the json file and it is marked as an EmbeddedResource as was the Resx files.

ErikApption commented 2 years ago

Hi @JerseyTechGuy, I had no luck finding any way to implement the ResourcePath in WASM because all the localizer action happens in non async mode and loading resources would require an async context. Have a look at the examples, in the most recent version the wasm does load resources through embedded resources.