Erweiterungsmethode hinzugefügt, um IStringLocalizer in ein dynamisches Objekt zu konvertieren.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace DigitalData.Core.API
|
||||
@@ -62,5 +63,20 @@ namespace DigitalData.Core.API
|
||||
/// <param name="localizer">The <see cref="IStringLocalizer"/> instance containing the localized strings.</param>
|
||||
/// <returns>A dictionary containing all localized strings, where the key is the name of the string and the value is the localized value.</returns>
|
||||
public static Dictionary<string, string> ToDictionary(this IStringLocalizer localizer) => localizer.GetAllStrings().ToDictionary(ls => ls.Name, ls => ls.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the localized strings from an <see cref="IStringLocalizer"/> to a dynamic object.
|
||||
/// </summary>
|
||||
/// <param name="localizer">The string localizer to get localized strings from.</param>
|
||||
/// <returns>A dynamic object containing all localized strings.</returns>
|
||||
public static dynamic ToDynamic(this IStringLocalizer localizer)
|
||||
{
|
||||
var expando = new ExpandoObject() as IDictionary<string, object>;
|
||||
foreach (var localizedString in localizer.GetAllStrings())
|
||||
{
|
||||
expando[localizedString.Name] = localizedString.Value;
|
||||
}
|
||||
return expando;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
DigitalData.Core.API/Properties/launchSettings.json
Normal file
12
DigitalData.Core.API/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"DigitalData.Core.API": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:50245;http://localhost:50246"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user