chore
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using Hangfire;
|
||||
using Atomx.Utils.Json;
|
||||
using Hangfire;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Atomx.Core.Jos
|
||||
{
|
||||
@@ -20,16 +22,56 @@ namespace Atomx.Core.Jos
|
||||
/// </summary>
|
||||
[AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||
[DisableConcurrentExecution(60)]
|
||||
public void Execute(string path)
|
||||
public async Task ExecuteAsync(string path, string culture, string data)
|
||||
{
|
||||
_logger.LogInformation("LocalizationJob executed at: {time}", DateTimeOffset.Now);
|
||||
// 在这里添加多语言本地化的具体任务逻辑
|
||||
}
|
||||
try
|
||||
{
|
||||
var translations = data.FromJson<Dictionary<string, string>>();
|
||||
|
||||
public void ResetCache()
|
||||
{
|
||||
_logger.LogInformation("LocalizationJob ResetCache executed at: {time}", DateTimeOffset.Now);
|
||||
// 在这里添加重置缓存的具体逻辑
|
||||
var fileName = $"{culture}.json";
|
||||
var filePath = Path.Combine(path, fileName);
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
_logger.LogInformation("Created Resources directory: {Path}", filePath);
|
||||
}
|
||||
|
||||
var json = await File.ReadAllTextAsync(filePath);
|
||||
var fileData = JsonSerializer.Deserialize<Dictionary<string, string>>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
if (fileData == null)
|
||||
{
|
||||
fileData = new Dictionary<string, string>();
|
||||
}
|
||||
foreach (var item in translations)
|
||||
{
|
||||
if (fileData.ContainsKey(item.Key))
|
||||
{
|
||||
fileData[item.Key] = item.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileData.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
json = JsonSerializer.Serialize(fileData, options);
|
||||
await File.WriteAllTextAsync(filePath, json);
|
||||
|
||||
|
||||
|
||||
_logger.LogInformation("Saved localization file for culture: {Culture} with {Count} translations",
|
||||
culture, translations.Count);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
_logger.LogError(ex, "Error saving localization file for culture: {Culture}", culture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user