Skip to content

Commit

Permalink
Add localization to error page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramo-Y committed Jul 13, 2024
1 parent 35c0392 commit 33736f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/BulkRename/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BulkRename;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Razor;
using Serilog;
using System.Globalization;
using System.Reflection;
Expand All @@ -11,7 +12,8 @@
startup.ConfigureServices(builder.Services);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddControllersWithViews()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);

builder.Services.AddLocalization(options =>
{
Expand Down
18 changes: 18 additions & 0 deletions src/BulkRename/Resources/SharedResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AnErrorOccuredHeader" xml:space="preserve">
<value>An error occurred while processing your request.</value>
</data>
<data name="DetailedErrorMessage" xml:space="preserve">
<value>&lt;strong&gt;The Development environment shouldn't be enabled for deployed applications.&lt;/strong&gt;
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the &lt;strong&gt;Development&lt;/strong&gt; environment by setting the &lt;strong&gt;ASPNETCORE_ENVIRONMENT&lt;/strong&gt; environment variable to &lt;strong&gt;Development&lt;/strong&gt;
and restarting the app.</value>
</data>
<data name="DevelopmentMode" xml:space="preserve">
<value>Development Mode</value>
</data>
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="History" xml:space="preserve">
<value>History</value>
</data>
Expand All @@ -141,6 +156,9 @@
<data name="SuccessfullyRenamedFiles" xml:space="preserve">
<value>Successfully renamed files</value>
</data>
<data name="SwappingToDevelopmentModeDisplay" xml:space="preserve">
<value>Swapping to &lt;strong&gt;Development&lt;/strong&gt; environment will display more detailed information about the error that occurred.</value>
</data>
<data name="WelcomeToBulkRename" xml:space="preserve">
<value>Welcome to BulkRename</value>
</data>
Expand Down
24 changes: 14 additions & 10 deletions src/BulkRename/Views/Shared/Error.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
@model ErrorViewModel
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization

@inject IStringLocalizer<SharedResource> SharedLocalizer
@inject IHtmlLocalizer<SharedResource> SharedHtmlLocalizer

@model ErrorViewModel

@{
ViewData["Title"] = "Error";
ViewData["Title"] = SharedLocalizer["Error"];
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
<h1 class="text-danger">@SharedLocalizer["Error"].</h1>
<h2 class="text-danger">@SharedLocalizer["AnErrorOccuredHeader"]</h2>

@if (Model?.ShowRequestId ?? false)
{
Expand All @@ -13,13 +20,10 @@
</p>
}

<h3>Development Mode</h3>
<h3>@SharedLocalizer["DevelopmentMode"]</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
@SharedHtmlLocalizer["SwappingToDevelopmentModeDisplay"]
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
@SharedHtmlLocalizer["DetailedErrorMessage"]
</p>

0 comments on commit 33736f2

Please sign in to comment.