Add project files.

This commit is contained in:
2025-08-20 11:07:36 +03:30
parent 3863c74931
commit 1a308a4069
899 changed files with 85379 additions and 0 deletions
@@ -0,0 +1,9 @@
namespace Elsa.Studio.Localization;
internal class DefaultLocalizationProvider : ILocalizationProvider
{
public string GetTranslation(string key)
{
return key;
}
}
@@ -0,0 +1,58 @@
using Microsoft.Extensions.Localization;
namespace Elsa.Studio.Localization;
/// <inheritdoc />
public class DefaultLocalizer(ILocalizationProvider provider) : ILocalizer
{
/// <inheritdoc />
public LocalizedString this[string key]
{
get
{
if (string.IsNullOrWhiteSpace(key))
return new LocalizedString(string.Empty, string.Empty, true);
var notFound = false;
var translation = provider.GetTranslation(key);
if (string.IsNullOrEmpty(translation))
{
translation = key;
notFound = true;
}
return new LocalizedString(key, translation, notFound);
}
}
/// <summary>
/// Gets the localized string with the specified key and formats it with the provided arguments.
/// </summary>
/// <param name="key">The key of the localized string.</param>
/// <param name="arguments">The arguments to format the localized string with.</param>
/// <returns>The localized string formatted with the provided arguments.</returns>
public LocalizedString this[string key, params object[] arguments]
{
get
{
if (string.IsNullOrWhiteSpace(key))
return new LocalizedString(string.Empty, string.Empty, true);
var notFound = false;
var translation = provider.GetTranslation(key);
if (string.IsNullOrEmpty(translation))
{
translation = string.Format(key, arguments);
notFound = true;
}
else
{
translation = string.Format(translation, arguments);
}
return new LocalizedString(key, translation, notFound);
}
}
}
@@ -0,0 +1,6 @@
namespace Elsa.Studio.Localization;
public interface ILocalizationProvider
{
string GetTranslation(string key);
}
@@ -0,0 +1,22 @@
using Microsoft.Extensions.Localization;
namespace Elsa.Studio.Localization;
/// <summary>
/// Interface for localization.
/// </summary>
public interface ILocalizer
{
/// <summary>
/// Gets the localized string for the given key.
/// </summary>
/// <param name="key">The key for the localized string.</param>
LocalizedString this[string key] { get; }
/// <summary>
/// Gets the localized string for the given key and formats it with the provided arguments.
/// </summary>
/// <param name="key">The key for the localized string.</param>
/// <param name="arguments">The arguments to format the localized string with.</param>
LocalizedString this[string key, params object[] arguments] { get; }
}