增加 国际化修改,触发更新json文件
parent
e3b9576a2d
commit
4f5b7be7b8
|
@ -17,7 +17,7 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
{
|
{
|
||||||
public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources);
|
public static string JsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources);
|
||||||
|
|
||||||
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value)
|
public static async Task AddOrUpdateJsonKeyValueAsync(string key, string value, string valueCN)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,15 +28,32 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
throw new BusinessValidationFailedException("国际化Json文件目录有误");
|
throw new BusinessValidationFailedException("国际化Json文件目录有误");
|
||||||
}
|
}
|
||||||
|
|
||||||
//将该目录下的国际化文件全部修改
|
var usJsonPath = Path.Combine(JsonFileFolder, StaticData.En_US_Json);
|
||||||
foreach (var filePath in Directory.GetFiles(JsonFileFolder).Where(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase)))
|
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
||||||
|
|
||||||
|
|
||||||
|
//更新json 文件 同时更新内存缓存的数据
|
||||||
|
foreach (var filePath in new string[] { usJsonPath, cnJsonPath })
|
||||||
{
|
{
|
||||||
var json = await File.ReadAllTextAsync(filePath);
|
var json = await File.ReadAllTextAsync(filePath);
|
||||||
|
|
||||||
JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
|
JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
|
||||||
|
|
||||||
// 添加或更新指定的键值对
|
// 添加或更新指定的键值对
|
||||||
jsonObject[key] = value;
|
|
||||||
|
if (filePath.Contains(StaticData.En_US_Json))
|
||||||
|
{
|
||||||
|
jsonObject[key] = value;
|
||||||
|
|
||||||
|
StaticData.En_US_Dic[key] = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jsonObject[key] = valueCN;
|
||||||
|
|
||||||
|
StaticData.Zh_CN_Dic[key] = valueCN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
await File.WriteAllTextAsync(filePath, jsonObject.ToString());
|
await File.WriteAllTextAsync(filePath, jsonObject.ToString());
|
||||||
|
|
||||||
|
@ -60,8 +77,6 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
var cnJsonPath = Path.Combine(JsonFileFolder, StaticData.Zh_CN_Json);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//本地静态文件国际化需要
|
//本地静态文件国际化需要
|
||||||
foreach (var tojsonItem in toJsonList)
|
foreach (var tojsonItem in toJsonList)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +97,10 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
|
|
||||||
public static void WatchJsonFile(string filePath)
|
public static void WatchJsonFile(string filePath)
|
||||||
{
|
{
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("国际化Json文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath));
|
FileSystemWatcher watcher = new FileSystemWatcher(Path.GetDirectoryName(filePath), Path.GetFileName(filePath));
|
||||||
watcher.Changed += (sender, e) => LoadJsonFile(filePath);
|
watcher.Changed += (sender, e) => LoadJsonFile(filePath);
|
||||||
|
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using IRaCIS.Core.Application.Interfaces;
|
using IRaCIS.Core.Application.Interfaces;
|
||||||
using IRaCIS.Core.Application.ViewModel;
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using IRaCIS.Core.Application.Helper;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
@ -75,6 +76,12 @@ namespace IRaCIS.Core.Application.Service
|
||||||
|
|
||||||
var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true, verifyExp1);
|
var entity = await _internationalizationRepository.InsertOrUpdateAsync(addOrEditInternationalization, true, verifyExp1);
|
||||||
|
|
||||||
|
if (addOrEditInternationalization.InternationalizationType == 1)
|
||||||
|
{
|
||||||
|
await InternationalizationHelper.AddOrUpdateJsonKeyValueAsync(entity.Code, entity.Value, entity.ValueCN);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return ResponseOutput.Ok(entity.Id.ToString());
|
return ResponseOutput.Ok(entity.Id.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue