https://github.com/semack/localization.aspnetcore.entityframework
Database independent ASP.NET Core localization library
https://github.com/semack/localization.aspnetcore.entityframework
asp-net-core asp-net-core-localization ef-localization localization sql-localization
Last synced: 16 days ago
JSON representation
Database independent ASP.NET Core localization library
- Host: GitHub
- URL: https://github.com/semack/localization.aspnetcore.entityframework
- Owner: semack
- License: mit
- Created: 2020-12-08T19:54:34.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-15T18:40:21.000Z (over 5 years ago)
- Last Synced: 2025-01-17T18:22:48.822Z (over 1 year ago)
- Topics: asp-net-core, asp-net-core-localization, ef-localization, localization, sql-localization
- Language: C#
- Homepage:
- Size: 784 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Localization.AspNetCore.EntityFramework
 
Database independent ASP.NET Core localization library using EntityFramework.
## Installation
Before using of the library [Nuget Package](https://www.nuget.org/packages/Localization.AspNetCore.EntityFramework/) must be installed.
`Install-Package Localization.AspNetCore.EntityFramework`
## Examples of usage
The examples are included to the current repository.
## Roadmap
- [x] EF integration
- [x] Import
- [x] Export
- [ ] Sync
- [ ] Admin Controller
## Configuration
Please see comments in code below:
```c#
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
{
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection"))
// Adding necessary localization models to existing database context
.UseLocalizationEntities();
});
services.AddDatabaseDeveloperPageExceptionFilter();
services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores();
// Registering Localizer and defining its configuration.
// Must be called before services.Configure
// and services.AddViewLocalization();
services.AddLocalization(options =>
{
{
options.FallBackBehavior = FallBackBehaviorEnum.DefaultCulture;
options.NamingConvention = NamingConventionEnum.FullTypeName;
options.CreateMissingTranslationsIfNotFound = true;
}
});
services.Configure(
options =>
{
var supportedCultures = new List
{
new CultureInfo("en-US"),
new CultureInfo("de-CH"),
new CultureInfo("fr-CH"),
new CultureInfo("it-CH")
};
options.DefaultRequestCulture = new RequestCulture("en-US", "en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
services.AddControllersWithViews()
.AddViewLocalization();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
var localizationOptions = app.ApplicationServices.GetService>();
app.UseRequestLocalization(localizationOptions?.Value);
app.UseDefaultFiles();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
// Adding Localizer Middleware
app.UseLocalization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
```
## License
Please see [LICENSE.md](LICENSE.md).
## Contribute
Contributions are welcome. Just open an Issue or submit a PR.
## Contact
You can reach me via my [email](mailto://semack@gmail.com).