Created
September 11, 2017 18:10
-
-
Save gzamudio/4db43b93ea73d49e062654fd124dab26 to your computer and use it in GitHub Desktop.
Example of use for LocalizationCultureCore NuGet Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"DescriptionPage": "Your application description page.", | |
"ContactPage": "Your contact page.", | |
"HomePage": "Home Page", | |
"HowToBuild": "Learn how to build ASP.NET apps that can run anywhere.", | |
"LearnMore": "Learn More", | |
"FeaturesInVSForModernWebApps": "There are powerful new features in Visual Studio for building modern web apps.", | |
"BringInLibraries": "Bring in libraries from NuGet, Bower, and npm, and automate tasks using Grunt or Gulp.", | |
"AzureDeploy": "Learn how Microsoft's Azure cloud platform allows you to build, deploy, and scale web apps.", | |
"Previous": "Previous", | |
"Next": "Next", | |
"About": "About", | |
"Contact": "Contact" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.Localization; | |
using Microsoft.EntityFrameworkCore; | |
using NetCoreBootstrap.Models.Database; | |
namespace NetCoreBootstrap.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
private readonly DbContextOptions<DataBaseContext> _options; | |
private readonly IHtmlLocalizer<HomeController> _localizer; | |
public HomeController(DbContextOptions<DataBaseContext> options, IHtmlLocalizer<HomeController> localizer) | |
{ | |
this._options = options; | |
this._localizer = localizer; | |
} | |
[HttpGet("")] | |
public IActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpGet("About")] | |
public IActionResult About() | |
{ | |
ViewData["Message"] = Localizer["DescriptionPage"]; | |
return View(); | |
} | |
[HttpGet("Contact")] | |
public IActionResult Contact() | |
{ | |
ViewData["Message"] = Localizer["ContactPage"]; | |
return View(); | |
} | |
[HttpGet("Error")] | |
public IActionResult Error() | |
{ | |
return View(); | |
} | |
public IHtmlLocalizer<HomeController> Localizer | |
{ | |
get { return this._localizer; } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Microsoft.AspNetCore.Mvc.Localization | |
@using System.Globalization; | |
@inject IViewLocalizer Localizer | |
@{ | |
ViewData["Title"] = Localizer["HomePage"]; | |
} | |
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000"> | |
<ol class="carousel-indicators"> | |
<li data-target="#myCarousel" data-slide-to="0" class="active"></li> | |
<li data-target="#myCarousel" data-slide-to="1"></li> | |
<li data-target="#myCarousel" data-slide-to="2"></li> | |
<li data-target="#myCarousel" data-slide-to="3"></li> | |
</ol> | |
<div class="carousel-inner" role="listbox"> | |
<div class="item active"> | |
<img src="~/images/banner1.svg" alt="ASP.NET" class="img-responsive" /> | |
<div class="carousel-caption" role="option"> | |
<p> | |
@Localizer["HowToBuild"] | |
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525028&clcid=0x409"> | |
@Localizer["LearnMore"] | |
</a> | |
</p> | |
</div> | |
</div> | |
<div class="item"> | |
<img src="~/images/banner2.svg" alt="Visual Studio" class="img-responsive" /> | |
<div class="carousel-caption" role="option"> | |
<p> | |
@Localizer["FeaturesInVSForModernWebApps"] | |
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525030&clcid=0x409"> | |
@Localizer["LearnMore"] | |
</a> | |
</p> | |
</div> | |
</div> | |
<div class="item"> | |
<img src="~/images/banner3.svg" alt="Package Management" class="img-responsive" /> | |
<div class="carousel-caption" role="option"> | |
<p> | |
@Localizer["BringInLibraries"] | |
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525029&clcid=0x409"> | |
@Localizer["LearnMore"] | |
</a> | |
</p> | |
</div> | |
</div> | |
<div class="item"> | |
<img src="~/images/banner4.svg" alt="Microsoft Azure" class="img-responsive" /> | |
<div class="carousel-caption" role="option"> | |
<p> | |
@Localizer["AzureDeploy"] | |
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525027&clcid=0x409"> | |
@Localizer["LearnMore"] | |
</a> | |
</p> | |
</div> | |
</div> | |
</div> | |
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> | |
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> | |
<span class="sr-only">@Localizer["Previous"]</span> | |
</a> | |
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | |
<span class="sr-only">@Localizer["Next"]</span> | |
</a> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Add framework services. | |
services.AddJsonLocalization(options => options.ResourcesPath = "Resources"); | |
CultureInfo.CurrentCulture = new CultureInfo(Configuration["DefaultCulture"]); | |
services.AddMvc().AddViewLocalization(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment