diff --git a/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml b/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml index 099e2cde..786a5a5c 100644 --- a/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml +++ b/Marechai/Areas/Identity/Pages/Shared/_LoginPartial.cshtml @@ -1,27 +1,30 @@ -@using Microsoft.AspNetCore.Identity +@using Marechai.Shared +@using Microsoft.AspNetCore.Identity +@using Microsoft.Extensions.Localization @inject SignInManager SignInManager @inject UserManager UserManager +@inject StringLocalizer L @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 173c4182..ff806414 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.928 + 3.0.99.933 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -112,4 +112,10 @@ true + + + ResXFileCodeGenerator + NewsService.es.Designer.cs + + \ No newline at end of file diff --git a/Marechai/Pages/Index.razor b/Marechai/Pages/Index.razor index eca32607..4049a2d0 100644 --- a/Marechai/Pages/Index.razor +++ b/Marechai/Pages/Index.razor @@ -1,8 +1,8 @@ @page "/" -@using Marechai.ViewModels @inherits OwningComponentBase +@inject IStringLocalizer L -

News

+

@L["News"]

@foreach (var news in _news) { diff --git a/Marechai/Pages/_Host.cshtml.cs b/Marechai/Pages/_Host.cshtml.cs new file mode 100644 index 00000000..6d5f0f61 --- /dev/null +++ b/Marechai/Pages/_Host.cshtml.cs @@ -0,0 +1,16 @@ +using System.Globalization; +using Microsoft.AspNetCore.Localization; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Marechai.Pages +{ + public class HostModel : PageModel + { + public void OnGet() => HttpContext.Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, + CookieRequestCultureProvider. + MakeCookieValue(new + RequestCulture(CultureInfo.CurrentCulture, + CultureInfo. + CurrentUICulture))); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/NewsService.es.resx b/Marechai/Resources/Services/NewsService.es.resx new file mode 100644 index 00000000..b98e4dad --- /dev/null +++ b/Marechai/Resources/Services/NewsService.es.resx @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Noticias + News + + + Nuevo ordenador en la base de datos + New computer in database + + + Nueva videoconsola en la base de datos + New console in database + + + Nuevo ordenador en la colección + New computer in collection + + + Nueva videoconsola en la base de datos + New console in collection + + + Ordenador actualizado en la base de datos + Updated computer in database + + + Videoconsola actualizada en la base de datos + Updated console in database + + + Ordenador actualizado en la colección + Updated computer in collection + + + Videoconsola actualizada en la colección + Updated console in collection + + \ No newline at end of file diff --git a/Marechai/Resources/Shared/NavMenu.es.resx b/Marechai/Resources/Shared/NavMenu.es.resx new file mode 100644 index 00000000..7e244243 --- /dev/null +++ b/Marechai/Resources/Shared/NavMenu.es.resx @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Noticias + News + + + ¡Hola {0}! + Salutes logged-in user + + + Cerrar sesión + Logout + + + Registrarse + Register + + + Iniciar sesión + Login + + + Acerca de + About + + \ No newline at end of file diff --git a/Marechai/Services/NewsService.cs b/Marechai/Services/NewsService.cs index 164818cb..b565f267 100644 --- a/Marechai/Services/NewsService.cs +++ b/Marechai/Services/NewsService.cs @@ -33,14 +33,20 @@ using System.Linq; using Marechai.Database; using Marechai.Database.Models; using Marechai.ViewModels; +using Microsoft.Extensions.Localization; namespace Marechai.Services { public class NewsService { - readonly MarechaiContext _context; + readonly MarechaiContext _context; + readonly IStringLocalizer _l; - public NewsService(MarechaiContext context) => _context = context; + public NewsService(MarechaiContext context, IStringLocalizer localizer) + { + _context = context; + _l = localizer; + } public List GetNews() { @@ -56,49 +62,49 @@ namespace Marechai.Services switch(@new.Type) { case NewsType.NewComputerInDb: - news.Add(new NewsViewModel(@new.AddedId, "New computer in database", @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New computer in database"], @new.Date, "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewConsoleInDb: - news.Add(new NewsViewModel(@new.AddedId, "New console in database", @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New console in database"], @new.Date, "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewComputerInCollection: - news.Add(new NewsViewModel(@new.AddedId, "New computer in collection", @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New computer in collection"], @new.Date, "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewConsoleInCollection: - news.Add(new NewsViewModel(@new.AddedId, "New console in collection", @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New console in collection"], @new.Date, "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedComputerInDb: - news.Add(new NewsViewModel(@new.AddedId, "Updated computer in database", @new.Date, "Machine", - $"{machine.Company.Name} {machine.Name}")); + news.Add(new NewsViewModel(@new.AddedId, _l["Updated computer in database"], @new.Date, + "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedConsoleInDb: - news.Add(new NewsViewModel(@new.AddedId, "Updated console in database", @new.Date, "Machine", - $"{machine.Company.Name} {machine.Name}")); + news.Add(new NewsViewModel(@new.AddedId, _l["Updated console in database"], @new.Date, + "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedComputerInCollection: - news.Add(new NewsViewModel(@new.AddedId, "Updated computer in collection", @new.Date, "Machine", - $"{machine.Company.Name} {machine.Name}")); + news.Add(new NewsViewModel(@new.AddedId, _l["Updated computer in collection"], @new.Date, + "Machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedConsoleInCollection: - news.Add(new NewsViewModel(@new.AddedId, "Updated console in collection", @new.Date, "Machine", - $"{machine.Company.Name} {machine.Name}")); + news.Add(new NewsViewModel(@new.AddedId, _l["Updated console in collection"], @new.Date, + "Machine", $"{machine.Company.Name} {machine.Name}")); break; diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 846ebdee..d929b798 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -28,15 +28,20 @@ // Copyright © 2003-2020 Natalia Portillo *******************************************************************************/ +using Marechai.Shared; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; namespace Marechai.Services { public static class Register { - internal static void RegisterServices(IServiceCollection services) => + internal static void RegisterServices(IServiceCollection services) + { + services.AddSingleton>(); - // TODO: User reflection + // TODO: Use reflection services.AddScoped(); + } } } \ No newline at end of file diff --git a/Marechai/Shared/MainLayout.razor b/Marechai/Shared/MainLayout.razor index c0e6dbd0..f9ed0564 100644 --- a/Marechai/Shared/MainLayout.razor +++ b/Marechai/Shared/MainLayout.razor @@ -1,4 +1,5 @@ @inherits LayoutComponentBase +@inject StringLocalizer L