Restructures project with feature-based organization
Refactors project structure to support modular, feature-driven development Introduces comprehensive language localization support Adds menu management with role-based access control Implements dynamic sidebar and theme switching capabilities Enhances project scalability and maintainability
This commit is contained in:
parent
fac7754d7a
commit
d7f3c55a2a
60 changed files with 3214 additions and 20 deletions
10
app/Features/Language/Services/ILocalizationService.cs
Normal file
10
app/Features/Language/Services/ILocalizationService.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using CalendarServer.Features.Language.Models;
|
||||
|
||||
namespace CalendarServer.Features.Language.Services;
|
||||
|
||||
public interface ILocalizationService
|
||||
{
|
||||
string Get(string key, string? culture = null);
|
||||
string CurrentCulture { get; }
|
||||
IEnumerable<SupportedCulture> GetSupportedCultures();
|
||||
}
|
||||
48
app/Features/Language/Services/JsonLocalizationService.cs
Normal file
48
app/Features/Language/Services/JsonLocalizationService.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System.Text.Json;
|
||||
using CalendarServer.Features.Language.Models;
|
||||
|
||||
namespace CalendarServer.Features.Language.Services;
|
||||
|
||||
public class JsonLocalizationService : ILocalizationService
|
||||
{
|
||||
private readonly string _translationsPath;
|
||||
|
||||
public JsonLocalizationService(IWebHostEnvironment env)
|
||||
{
|
||||
_translationsPath = Path.Combine(env.ContentRootPath, "Features", "Language", "Translations");
|
||||
}
|
||||
|
||||
public string CurrentCulture => "en";
|
||||
|
||||
public string Get(string key, string? culture = null)
|
||||
{
|
||||
culture ??= CurrentCulture;
|
||||
var filePath = Path.Combine(_translationsPath, $"{culture}.json");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
return key;
|
||||
|
||||
var json = File.ReadAllText(filePath);
|
||||
var doc = JsonDocument.Parse(json);
|
||||
|
||||
var parts = key.Split('.');
|
||||
JsonElement current = doc.RootElement;
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (!current.TryGetProperty(part, out current))
|
||||
return key;
|
||||
}
|
||||
|
||||
return current.GetString() ?? key;
|
||||
}
|
||||
|
||||
public IEnumerable<SupportedCulture> GetSupportedCultures()
|
||||
{
|
||||
return new List<SupportedCulture>
|
||||
{
|
||||
new() { Code = "da", Name = "Danish", NativeName = "Dansk" },
|
||||
new() { Code = "en", Name = "English", NativeName = "English" }
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue