设置静态国际化+测试ok
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2024-10-16 10:40:38 +08:00
parent 8be3cc9e78
commit 663a6c7f5c
5 changed files with 53 additions and 23 deletions

View File

@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Localization;
using Newtonsoft.Json;
using Serilog;
using System;
@ -259,6 +260,9 @@ var hangfireJobService = app.Services.GetRequiredService<IIRaCISHangfireJob>();
await hangfireJobService.InitHangfireJobTaskAsync();
var localizer = app.Services.GetRequiredService<IStringLocalizer>();
I18n.SetLocalizer(localizer);
try
{
#region 运行环境 部署平台

View File

@ -28,7 +28,6 @@ using NPOI.XWPF.UserModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using Tea;
namespace IRaCIS.Core.Application.Service
@ -57,12 +56,23 @@ namespace IRaCIS.Core.Application.Service
}
[AllowAnonymous]
public IResponseOutput GetTest(Guid trialId,int num, TestModel testModel)
public IResponseOutput GetTest()
{
//throw new BusinessValidationFailedException("手动抛出的异常");
return ResponseOutput.Ok(_userInfo.IP);
}
public IResponseOutput GetTestI18n()
{
var isEn_US = CultureInfo.CurrentCulture.Name == StaticData.CultureInfo.en_US;
//CultureInfo.CurrentCulture = new CultureInfo(StaticData.CultureInfo.en_US);
//CultureInfo.CurrentUICulture = new CultureInfo(StaticData.CultureInfo.en_US);
return ResponseOutput.Ok(I18n.T("TaskAllocation_DoctorConfigExists"));
}
}

View File

@ -71,23 +71,9 @@ namespace IRaCIS.Core.Infra.EFCore
bool autoSave = false, bool ignoreQueryFilter = false) where T : Entity;
}
public class Repository : IRepository
public class Repository(IRaCISDBContext _dbContext, IMapper _mapper, IUserInfo _userInfo) : IRepository
{
#region 构造 基本
private IRaCISDBContext _dbContext { get; }
public IMapper _mapper { get; set; }
public IUserInfo _userInfo { get; set; }
public IStringLocalizer _localizer { get; set; }
public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo, IStringLocalizer localizer)
{
_localizer = localizer;
_dbContext = dbContext;
_mapper = mapper;
_userInfo = userInfo;
}
/// <summary>
/// 设置是使用哪个仓储 默认不跟踪
@ -171,7 +157,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (dbEntity == null)
{
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
throw new BusinessValidationFailedException(I18n.T("Repository_UpdateError"));
}
var dbBeforEntity = dbEntity.Clone();
@ -450,7 +436,6 @@ namespace IRaCIS.Core.Infra.EFCore
}
#endregion

View File

@ -100,7 +100,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (dbEntity == null)
{
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
throw new BusinessValidationFailedException(I18n.T("Repository_UpdateError"));
}
var dbBeforEntity = dbEntity.Clone();
@ -156,7 +156,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (searchEntity == null)
{
throw new BusinessValidationFailedException(_localizer["Repository_UpdateError"]);
throw new BusinessValidationFailedException(I18n.T("Repository_UpdateError"));
}
_dbContext.EntityModifyPartialFiled(searchEntity, updateFactory);
@ -208,7 +208,7 @@ namespace IRaCIS.Core.Infra.EFCore
if (waitDelete == null)
{
throw new BusinessValidationFailedException(_localizer["Repository_DeleteError"]);
throw new BusinessValidationFailedException(I18n.T("Repository_DeleteError"));
}
await DeleteAsync(waitDelete, autoSave);

View File

@ -0,0 +1,31 @@
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IRaCIS.Core.Infrastructure.Extention;
public static class I18n
{
private static IStringLocalizer _localizer;
public static void SetLocalizer(IStringLocalizer localizer)
{
_localizer = localizer;
}
public static string T(string key)
{
return _localizer[key];
}
public static string T(string key, params object[] arguments)
{
return _localizer[key, arguments];
}
}