Пример #1
0
 internal I18nTextRepository(IServiceProvider serviceProvider, I18nTextOptions options)
 {
     if (options.IsWasm())
     {
         var httpClientFactory = serviceProvider.GetRequiredService <IHttpClientFactory>();
         this.HttpClient             = httpClientFactory.CreateClient(options.HttpClientName);
         this.ReadJsonAsTextMapAsync = this.ReadJsonAsTextMapWasmAsync;
     }
     else
     {
         this.ReadJsonAsTextMapAsync = this.GetReadJsonAsTextMapServerAsync();
     }
 }
Пример #2
0
        internal I18nTextRepository(IServiceProvider serviceProvider, I18nTextOptions options)
        {
            var isWasm = options.IsWasm?.Invoke() ?? I18nTextDependencyInjection.IsWasm;

            if (isWasm)
            {
                var httpClientFactory = serviceProvider.GetRequiredService <IHttpClientFactory>();
                this.HttpClient             = httpClientFactory.CreateClient(options.HttpClientName);
                this.ReadJsonAsTextMapAsync = this.ReadJsonAsTextMapWasmAsync;
            }
            else
            {
                this.ReadJsonAsTextMapAsync = this.GetReadJsonAsTextMapServerAsync();
            }
        }
        internal I18nText(Type typeOfStartUp, IServiceProvider serviceProvider, I18nTextOptions options)
        {
            this.RunningOnClientSide = RuntimeInformation.OSDescription == "web";
            if (this.RunningOnClientSide)
            {
                this.HttpClient = serviceProvider.GetService(typeof(HttpClient)) as HttpClient;
            }
            else
            {
                var blazorPathInfoService = serviceProvider.GetService(typeof(BlazorPathInfoService)) as BlazorPathInfoService;
                this.BlazorPathInfo = blazorPathInfoService.GetPathInfo(typeOfStartUp);
            }

            this.ServiceProvider = serviceProvider;
            this.Options         = options;

            this.InitLangTask = this.Options.GetInitialLanguageAsync.Invoke(this.ServiceProvider, this.Options).ContinueWith(t =>
            {
                _CurrentLanguage = t.IsCompleted ? t.Result : "en";
            });
        }
Пример #4
0
 internal I18nText(IServiceProvider serviceProvider, I18nTextOptions options)
 {
     this.ServiceProvider    = serviceProvider;
     this.I18nTextRepository = serviceProvider.GetRequiredService <I18nTextRepository>();
     this.Options            = options;
 }
        internal static Task PersistCurrentLanguageAsync(IServiceProvider serviceProvider, string langCode, I18nTextOptions options)
        {
            var jsRuntime = serviceProvider.GetService(typeof(IJSRuntime)) as IJSRuntime;

            return(jsRuntime.InvokeAsync <object>("Toolbelt.Blazor.I18nText.setCurrentLang", langCode, options.PersistanceLevel));
        }
        internal static Task <string> GetInitialLanguageAsync(IServiceProvider serviceProvider, I18nTextOptions options)
        {
            var jsRuntime = serviceProvider.GetService(typeof(IJSRuntime)) as IJSRuntime;

            return(jsRuntime.InvokeAsync <string>("Toolbelt.Blazor.I18nText.initLang", options.PersistanceLevel));
        }
        private async ValueTask PersistCurrentLanguageAsync(IServiceProvider serviceProvider, string langCode, I18nTextOptions options)
        {
            var jsRuntime = await GetJSRuntimeAsync();

            await jsRuntime.InvokeVoidAsync("Toolbelt.Blazor.I18nText.setCurrentLang", langCode, options.PersistanceLevel);
        }
        private async ValueTask <string> GetInitialLanguageAsync(IServiceProvider serviceProvider, I18nTextOptions options)
        {
            var jsRuntime = await GetJSRuntimeAsync();

            return(await jsRuntime.InvokeAsync <string>("Toolbelt.Blazor.I18nText.initLang", options.PersistanceLevel));
        }