Skip to content

Commit

Permalink
add l10n to api messages
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Oct 20, 2023
1 parent b7557cc commit 33fa110
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using Microsoft.Extensions.Localization;

namespace KratosSelfService.Services.l10n;
namespace KratosSelfService;

/// <summary>
/// Custom localisation strings, This class have to be in the root project directory
/// </summary>
/// <param name="localizer"></param>
public class CustomTranslator(IStringLocalizer<CustomTranslator> localizer) : ICustomTranslator
{
private IStringLocalizer<CustomTranslator> Localizer { get; } = localizer;
Expand Down
3 changes: 1 addition & 2 deletions KratosSelfService/Extensions/GroupEnumExt.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using KratosSelfService.Services.l10n;
using Ory.Kratos.Client.Model;
using Ory.Kratos.Client.Model;

namespace KratosSelfService.Extensions;

Expand Down
2 changes: 1 addition & 1 deletion KratosSelfService/Models/KratosUiTextMessageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace KratosSelfService.Models;

public record KratosUiTextMessageModel(KratosUiText Text, string CssClass);
public record KratosUiTextMessageModel(KratosUiText UiText, string Content, string CssClass);
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using Microsoft.Extensions.Localization;

namespace KratosSelfService.Services.l10n;
namespace KratosSelfService;

/// <summary>
/// Localized strings from ory/elements.
/// https://github.com/ory/elements/tree/main/src/locales
/// This class has to be in the root project directory.
/// </summary>
/// <param name="localizer"></param>
public class OryElementsTranslator(IStringLocalizer<OryElementsTranslator> localizer) : IOryElementsTranslator
{
private IStringLocalizer<OryElementsTranslator> Localizer { get; } = localizer;
Expand Down
1 change: 0 additions & 1 deletion KratosSelfService/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Globalization;
using KratosSelfService.Services;
using KratosSelfService.Services.l10n;
using Microsoft.AspNetCore.Localization;

namespace KratosSelfService;
Expand Down
7 changes: 4 additions & 3 deletions KratosSelfService/ViewComponents/KratosUiTextMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

namespace KratosSelfService.ViewComponents;

public class KratosUiTextMessage : ViewComponent
public class KratosUiTextMessage(IOryElementsTranslator oryTranslator) : ViewComponent
{
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiText text)
public async Task<ViewViewComponentResult> InvokeAsync(KratosUiText uiText)
{
var model = new KratosUiTextMessageModel(text, GetCssClass(text.Type));
var content = oryTranslator.Get($"identities.messages.{uiText.Id}");
var model = new KratosUiTextMessageModel(uiText, content, GetCssClass(uiText.Type));
return View("Default", model);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@model KratosUiTextMessageModel

<div class="message @Model.CssClass p-2" id="@Model.Text.Id">
@Model.Text.Text
<div class="message @Model.CssClass p-2" id="@Model.UiText.Id">
@Model.Content
</div>
1 change: 0 additions & 1 deletion KratosSelfService/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@using KratosSelfService
@using KratosSelfService.Models
@using KratosSelfService.Services.l10n
@using Ory.Kratos.Client.Model
@inject IOryElementsTranslator OryTranslator
@inject ICustomTranslator CustomTranslator
Expand Down

0 comments on commit 33fa110

Please sign in to comment.