在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):valdisiljuconoks/localization-provider-core开源软件地址(OpenSource Url):https://github.com/valdisiljuconoks/localization-provider-core开源编程语言(OpenSource Language):C# 77.1%开源软件介绍(OpenSource Introduction):LocalizationProvider for .NET CoreDatabase driven localization provider for .NET Core applications. v7.0 is FINALLY OUT!Please read more in this blog post! Supporting LocalizationProviderIf you find this library useful, cup of coffee would be awesome! You can support further development of the library via Paypal. What is the LocalizationProvider project?LocalizationProvider project is Asp.Net Mvc web application localization provider on steriods. Giving you main following features:
What's new in v6?Please refer to this post to read more about new features in v6. Project StructureDatabase localization provider is split into main abstraction projects and .NET Core support project (this). Getting StartedBare Minimum to Start WithBelow are code fragments that are essential to get started with localization provider. Install required packages:
Following service configuration (usually in public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// add your authorization provider (asp.net identity, identity server, which ever..)
services
.AddControllersWithViews()
.AddMvcLocalization();
services.AddRazorPages();
services.AddRouting();
services.AddDbLocalizationProvider(_ =>
{
_.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
...
});
services.AddDbLocalizationProviderAdminUI(_ =>
{
...
});
}
...
} And following setup of the application is required as minimum (also usually located in public class Startup
{
...
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseDbLocalizationProvider();
app.UseDbLocalizationProviderAdminUI();
app.UseDbLocalizationClientsideProvider(); //assuming that you like also Javascript
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapDbLocalizationAdminUI();
endpoints.MapDbLocalizationClientsideProvider();
});
}
} You can grab some snippets form this sample using System.Collections.Generic;
using System.Globalization;
using DbLocalizationProvider.AdminUI.AspNetCore;
using DbLocalizationProvider.AdminUI.AspNetCore.Routing;
using DbLocalizationProvider.AspNetCore;
using DbLocalizationProvider.AspNetCore.ClientsideProvider.Routing;
using DbLocalizationProvider.Core.AspNetSample.Data;
using DbLocalizationProvider.Core.AspNetSample.Resources;
using DbLocalizationProvider.Storage.SqlServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Localization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace SampleApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(
options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services
.AddDefaultIdentity<IdentityUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services
.AddControllersWithViews()
.AddMvcLocalization();
services.AddRazorPages();
services.AddRouting();
var supportedCultures = new List<CultureInfo> { new CultureInfo("sv"), new CultureInfo("no"), new CultureInfo("en") };
services.Configure<RequestLocalizationOptions>(opts =>
{
opts.DefaultRequestCulture = new RequestCulture("en");
opts.SupportedCultures = supportedCultures;
opts.SupportedUICultures = supportedCultures;
});
services.AddDbLocalizationProvider(_ =>
{
_.EnableInvariantCultureFallback = true;
_.ScanAllAssemblies = true;
_.FallbackCultures.Try(supportedCultures);
_.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
});
services.AddDbLocalizationProviderAdminUI(_ =>
{
_.RootUrl = "/localization-admin";
_.ShowInvariantCulture = true;
_.ShowHiddenResources = false;
_.DefaultView = ResourceListView.Tree;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(options.Value);
app.UseRouting();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseDbLocalizationProvider();
app.UseDbLocalizationProviderAdminUI();
app.UseDbLocalizationClientsideProvider();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
endpoints.MapDbLocalizationAdminUI();
endpoints.MapDbLocalizationClientsideProvider();
});
}
}
} Also you can refer to sample app in GitHub for some more hints if needed. More Detailed Help
GitHub Source Code Structure.NET Core support project has its own repo while main abstraction projects are included as submodules here. How to ContributeIt's super cool if you read this section and are interesed how to help the library. Forking and playing around sample application is the fastest way to understand how localization provider is working and how to get started. Forking and cloning repo is first step you do. Keep in mind that provider is split into couple repositories to keep thigns separated. Additional repos are pulled in as submodules. If you Git client does not support automatic checkout of the submodules, just execute this command at the root of the checkout directory:
Building AdminUI.AspNetCore ProjectYou will need to run More Info
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论