修改静态文件国际化方式
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-10-16 11:06:17 +08:00
parent 663a6c7f5c
commit 7d07e18853
14 changed files with 35 additions and 56 deletions

View File

@ -77,7 +77,7 @@ namespace IRaCIS.Core.Application.Service.BusinessFilter
else if(statusCode != 200&&!(objectResult.Value is IResponseOutput)) else if(statusCode != 200&&!(objectResult.Value is IResponseOutput))
{ {
//---程序错误,请联系开发人员。 //---程序错误,请联系开发人员。
var apiResponse = ResponseOutput.NotOk(StaticData.International("UnifiedAPI_ProgramError")); var apiResponse = ResponseOutput.NotOk(I18n.T("UnifiedAPI_ProgramError"));
objectResult.Value = apiResponse; objectResult.Value = apiResponse;
objectResult.DeclaredType = apiResponse.GetType(); objectResult.DeclaredType = apiResponse.GetType();

View File

@ -30,9 +30,9 @@ public class ProjectExceptionFilter(ILogger<ProjectExceptionFilter> _logger, ISt
var info = string.Empty; var info = string.Empty;
if (!string.IsNullOrWhiteSpace(error!.LocalizedKey) && StaticData.Log_Locoalize_Dic.ContainsKey(error!.LocalizedKey)) if (!string.IsNullOrWhiteSpace(error!.LocalizedKey) && StaticData.Localizer_Dev_Dic.ContainsKey(error!.LocalizedKey))
{ {
info = $"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}"; info = $"[{error!.LocalizedKey}]:{StaticData.Localizer_Dev_Dic[error!.LocalizedKey]}";
} }

View File

@ -83,7 +83,7 @@ public class UnifiedApiResultFilter : Attribute, IAsyncResultFilter
else if (statusCode != 200 && !(objectResult.Value is IResponseOutput)) else if (statusCode != 200 && !(objectResult.Value is IResponseOutput))
{ {
//---程序错误,请联系开发人员。 //---程序错误,请联系开发人员。
var apiResponse = ResponseOutput.NotOk(StaticData.International("UnifiedAPI_ProgramError")); var apiResponse = ResponseOutput.NotOk(I18n.T("UnifiedAPI_ProgramError"));
objectResult.Value = apiResponse; objectResult.Value = apiResponse;
objectResult.DeclaredType = apiResponse.GetType(); objectResult.DeclaredType = apiResponse.GetType();

View File

@ -39,9 +39,9 @@ public class GlobalExceptionHandler(IStringLocalizer _localizer, ILogger<GlobalE
var info = string.Empty; var info = string.Empty;
if (!string.IsNullOrWhiteSpace(error!.LocalizedKey) && StaticData.Log_Locoalize_Dic.ContainsKey(error!.LocalizedKey)) if (!string.IsNullOrWhiteSpace(error!.LocalizedKey) && StaticData.Localizer_Dev_Dic.ContainsKey(error!.LocalizedKey))
{ {
info = $"[{error!.LocalizedKey}]:{StaticData.Log_Locoalize_Dic[error!.LocalizedKey]}"; info = $"[{error!.LocalizedKey}]:{StaticData.Localizer_Dev_Dic[error!.LocalizedKey]}";
} }
httpContext.Response.WriteAsJsonAsync(ResponseOutput.NotOk(exception.Message, "", error!.Code, localizedInfo: info)); httpContext.Response.WriteAsJsonAsync(ResponseOutput.NotOk(exception.Message, "", error!.Code, localizedInfo: info));

View File

@ -135,7 +135,7 @@ public static class FileStoreHelper
if (doc == null) if (doc == null)
{ {
//---数据库没有找到对应的数据模板文件,请联系系统运维人员。 //---数据库没有找到对应的数据模板文件,请联系系统运维人员。
throw new BusinessValidationFailedException(StaticData.International("FileStore_TemplateFileNotFound")); throw new BusinessValidationFailedException(I18n.T("FileStore_TemplateFileNotFound"));
} }
var filePath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, doc.Path); var filePath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, doc.Path);
@ -143,7 +143,7 @@ public static class FileStoreHelper
if (!System.IO.File.Exists(filePath)) if (!System.IO.File.Exists(filePath))
{ {
//---数据模板文件存储路径上未找对应文件,请联系系统运维人员。 //---数据模板文件存储路径上未找对应文件,请联系系统运维人员。
throw new BusinessValidationFailedException(StaticData.International("FileStore_TemplateFileStoragePathInvalid")); throw new BusinessValidationFailedException(I18n.T("FileStore_TemplateFileStoragePathInvalid"));
} }
return (filePath, isEn_US ? doc.Name.Trim('/') : doc.NameCN.Trim('/')); return (filePath, isEn_US ? doc.Name.Trim('/') : doc.NameCN.Trim('/'));
@ -269,7 +269,7 @@ public static class FileStoreHelper
{ {
//---解析Json文件配置出现问题 //---解析Json文件配置出现问题
throw new BusinessValidationFailedException(StaticData.International("SysMon_JsonConfig") + e.Message); throw new BusinessValidationFailedException(I18n.T("SysMon_JsonConfig") + e.Message);
} }
//默认存储的路径 //默认存储的路径

View File

@ -49,7 +49,7 @@ public static class InternationalizationHelper
StaticData.En_US_Dic[item.Code] = item.Value; StaticData.En_US_Dic[item.Code] = item.Value;
//日志记录该信息方便自己人看, 返回给客户的是配置的 //日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[item.Code] = item.Description; StaticData.Localizer_Dev_Dic[item.Code] = item.Description;
} }
} }
else else
@ -93,7 +93,7 @@ public static class InternationalizationHelper
StaticData.En_US_Dic[key] = value; StaticData.En_US_Dic[key] = value;
//日志记录该信息方便自己人看, 返回给客户的是配置的 //日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[key] = description; StaticData.Localizer_Dev_Dic[key] = description;
} }
else else
{ {
@ -134,7 +134,7 @@ public static class InternationalizationHelper
StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN; StaticData.Zh_CN_Dic[tojsonItem.Code] = tojsonItem.ValueCN;
//日志记录该信息方便自己人看, 返回给客户的是配置的 //日志记录该信息方便自己人看, 返回给客户的是配置的
StaticData.Log_Locoalize_Dic[tojsonItem.Code] = tojsonItem.Description; StaticData.Localizer_Dev_Dic[tojsonItem.Code] = tojsonItem.Description;
} }
File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic)); File.WriteAllText(usJsonPath, JsonConvert.SerializeObject(StaticData.En_US_Dic));
@ -145,11 +145,11 @@ public static class InternationalizationHelper
if (!File.Exists(usJsonPath) || !File.Exists(cnJsonPath)) if (!File.Exists(usJsonPath) || !File.Exists(cnJsonPath))
{ {
throw new BusinessValidationFailedException(StaticData.International("IRaCISCHangfireJob_FileNotFound")); throw new BusinessValidationFailedException(I18n.T("IRaCISCHangfireJob_FileNotFound"));
} }
// //监测Json文件变更 实时刷新数据 //监测Json文件变更 实时刷新数据
FileSystemWatcher_US = new FileSystemWatcher FileSystemWatcher_US = new FileSystemWatcher

View File

@ -42,7 +42,7 @@ public static class SendEmailHelper
{ {
//---邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员 //---邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员
throw new Exception(StaticData.International("SendEmail_SendFail"), new Exception(ex.Message)); throw new Exception(I18n.T("SendEmail_SendFail"), new Exception(ex.Message));
} }
@ -82,7 +82,7 @@ public static class SendEmailHelper
if (sMTPEmailConfig.ToMailAddressList.Count == 0) if (sMTPEmailConfig.ToMailAddressList.Count == 0)
{ {
//---没有收件人 //---没有收件人
throw new ArgumentException(StaticData.International("SendEmail_NoRecipient")); throw new ArgumentException(I18n.T("SendEmail_NoRecipient"));
} }
else else
{ {

View File

@ -397,7 +397,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
if (_fusionCache.GetOrDefault<Guid>(CacheKeys.TrialTaskStudyUidDBLock(incommand.TrialId, incommand.VisitTaskId, incommand.Study.StudyInstanceUid)) != Guid.Empty) if (_fusionCache.GetOrDefault<Guid>(CacheKeys.TrialTaskStudyUidDBLock(incommand.TrialId, incommand.VisitTaskId, incommand.Study.StudyInstanceUid)) != Guid.Empty)
{ {
//---当前已有人正在上传和归档该检查! //---当前已有人正在上传和归档该检查!
return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress")); return ResponseOutput.NotOk(I18n.T("UploadDownLoad_ArchiveInProgress"));
} }
else else
{ {

View File

@ -102,7 +102,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
if (cacheValue != Guid.Empty && cacheValue != _userInfo.Id) if (cacheValue != Guid.Empty && cacheValue != _userInfo.Id)
{ {
//---当前已有人正在上传和归档该检查! //---当前已有人正在上传和归档该检查!
return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress")); return ResponseOutput.NotOk(I18n.T("UploadDownLoad_ArchiveInProgress"));
} }
else else
{ {
@ -134,7 +134,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
if (_fusionCache.GetOrDefault<Guid>(CacheKeys.TrialStudyUidDBLock(incommand.TrialId, incommand.Study.StudyInstanceUid)) != Guid.Empty) if (_fusionCache.GetOrDefault<Guid>(CacheKeys.TrialStudyUidDBLock(incommand.TrialId, incommand.Study.StudyInstanceUid)) != Guid.Empty)
{ {
//---当前已有人正在上传和归档该检查! //---当前已有人正在上传和归档该检查!
return ResponseOutput.NotOk(StaticData.International("UploadDownLoad_ArchiveInProgress")); return ResponseOutput.NotOk(I18n.T("UploadDownLoad_ArchiveInProgress"));
} }
else else
{ {

View File

@ -4,3 +4,4 @@ global using System;
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.ComponentModel.DataAnnotations; global using System.ComponentModel.DataAnnotations;
global using System.ComponentModel.DataAnnotations.Schema; global using System.ComponentModel.DataAnnotations.Schema;
global using IRaCIS.Core.Infrastructure.Extention;

View File

@ -62,7 +62,7 @@ public class ReadingQuestionCriterionTrial : BaseAddAuditEntity
[Comment("全局阅片评估更新类型")] [Comment("全局阅片评估更新类型")]
public string GlobalUpdateType { get; set; } = string.Empty; public string GlobalUpdateType { get; set; } = string.Empty;
[Comment("评估原因")] [Comment("评估原因")]
public string EvaluationReason { get; set; } = StaticData.International("CriterionTrial_EvaluationReason"); public string EvaluationReason { get; set; } = I18n.T("CriterionTrial_EvaluationReason");
[Comment("是否显示详情")] [Comment("是否显示详情")]
public bool IsShowDetail { get; set; } = true; public bool IsShowDetail { get; set; } = true;

View File

@ -132,7 +132,7 @@ public partial class Trial : BaseFullDeleteAuditEntity
public bool VisitPlanConfirmed { get; set; } public bool VisitPlanConfirmed { get; set; }
[Comment("受试者编号具体规则")] [Comment("受试者编号具体规则")]
public string SubjectCodeRule { get; set; } = StaticData.International("Trial_number"); public string SubjectCodeRule { get; set; } = I18n.T("Trial_number");
[Comment("是否 提醒受试者编号规则")] [Comment("是否 提醒受试者编号规则")]
public bool IsNoticeSubjectCodeRule { get; set; } = true; public bool IsNoticeSubjectCodeRule { get; set; } = true;

View File

@ -117,9 +117,9 @@ namespace IRaCIS.Core.Infrastructure.Extention
var info = string.Empty; var info = string.Empty;
if (!string.IsNullOrWhiteSpace(key) && StaticData.Log_Locoalize_Dic.ContainsKey(key)) if (!string.IsNullOrWhiteSpace(key) && StaticData.Localizer_Dev_Dic.ContainsKey(key))
{ {
info = $"[{key}]:{StaticData.Log_Locoalize_Dic[key]}"; info = $"[{key}]:{StaticData.Localizer_Dev_Dic[key]}";
} }
return new ResponseOutput<string>().NotOk(msg, code: code, localizedInfo: info); return new ResponseOutput<string>().NotOk(msg, code: code, localizedInfo: info);

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -12,7 +13,7 @@ public static class StaticData
public static Dictionary<string, string> Zh_CN_Dic = new Dictionary<string, string>(); public static Dictionary<string, string> Zh_CN_Dic = new Dictionary<string, string>();
public static Dictionary<string, string> Log_Locoalize_Dic = new Dictionary<string, string>(); public static Dictionary<string, string> Localizer_Dev_Dic = new Dictionary<string, string>();
#region 国际化 #region 国际化
@ -33,44 +34,21 @@ public static class StaticData
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <returns></returns> /// <returns></returns>
public static string International(string key, params object?[] args) public static string I18n(string key, params object?[] args)
{ {
try var isEn_US = System.Globalization.CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
{
return string.Format(GetLanguageDictionary(key), args);
}
catch (Exception)
{
return string.Empty; if (isEn_US)
{
return En_US_Dic[key];
}
else
{
return Zh_CN_Dic[key];
} }
} }
public static string GetLanguageDictionary(string key)
{
try
{
var type = Thread.CurrentThread.CurrentUICulture.Name;
if (type == "zh-CN")
{
return Zh_CN_Dic[key];
}
else
{
return En_US_Dic[key];
}
}
catch (Exception)
{
return string.Empty;
}
}
#endregion #endregion
#region 字典表项固定值 #region 字典表项固定值