Add project files.

This commit is contained in:
Khwezi Mngoma
2026-06-05 22:07:25 +02:00
parent 59ea7de742
commit 437e8c5c08
978 changed files with 151911 additions and 0 deletions
@@ -0,0 +1,59 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// https://github.com/aspnet/Extensions/blob/master/src/Localization/Abstractions/src/StringLocalizerOfT.cs
// Modified by Jan Škoruba
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.Localization;
namespace LiteCharmsSecurity.STS.Identity.Helpers.Localization
{
public class GenericControllerLocalizer<TResourceSource> : IGenericControllerLocalizer<TResourceSource>
{
private IStringLocalizer _localizer;
/// <summary>
/// Creates a new <see cref="T:Microsoft.Extensions.Localization.StringLocalizer`1" />.
/// </summary>
/// <param name="factory">The <see cref="T:Microsoft.Extensions.Localization.IStringLocalizerFactory" /> to use.</param>
public GenericControllerLocalizer(IStringLocalizerFactory factory)
{
if (factory == null) throw new ArgumentNullException(nameof(factory));
var type = typeof(TResourceSource);
var assemblyName = type.GetTypeInfo().Assembly.GetName().Name;
var typeName = type.Name.Remove(type.Name.IndexOf('`'));
var baseName = (type.Namespace + "." + typeName).Substring(assemblyName.Length).Trim('.');
_localizer = factory.Create(baseName, assemblyName);
}
public virtual LocalizedString this[string name]
{
get
{
if (name == null)
throw new ArgumentNullException(nameof(name));
return _localizer[name];
}
}
public virtual LocalizedString this[string name, params object[] arguments]
{
get
{
if (name == null)
throw new ArgumentNullException(nameof(name));
return _localizer[name, arguments];
}
}
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
{
return _localizer.GetAllStrings(includeParentCultures);
}
}
}
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Microsoft.Extensions.Localization;
namespace LiteCharmsSecurity.STS.Identity.Helpers.Localization
{
public interface IGenericControllerLocalizer<out T>
{
LocalizedString this[string name] { get; }
LocalizedString this[string name, params object[] arguments] { get; }
IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures);
}
}
@@ -0,0 +1,23 @@
// Copyright (c) Jan Škoruba. All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
using Skoruba.Duende.IdentityServer.Shared.Configuration.Configuration.Identity;
namespace LiteCharmsSecurity.STS.Identity.Helpers.Localization
{
public static class LoginPolicyResolutionLocalizer
{
public static string GetUserNameLocalizationKey(LoginResolutionPolicy policy)
{
switch (policy)
{
case LoginResolutionPolicy.Username:
return "Username";
case LoginResolutionPolicy.Email:
return "Email";
default:
return "Username";
}
}
}
}