committed by
GitHub
70 changed files with 754 additions and 680 deletions
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Remove="LINGYUN\Abp\AspNetCore\Mvc\Localization\Resources\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="LINGYUN\Abp\AspNetCore\Mvc\Localization\Resources\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="$(VoloAbpPackageVersion)" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,43 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.Localization; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Localization.Resources.AbpLocalization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization; |
|||
|
|||
[DependsOn(typeof(AbpAspNetCoreMvcModule))] |
|||
public class AbpAspNetCoreMvcLocalizationModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
|||
{ |
|||
options.AddAssemblyResource( |
|||
typeof(AbpLocalizationResource), |
|||
typeof(AbpAspNetCoreMvcLocalizationModule).Assembly); |
|||
}); |
|||
|
|||
PreConfigure<IMvcBuilder>(mvcBuilder => |
|||
{ |
|||
mvcBuilder.AddApplicationPartIfNotExists(typeof(AbpAspNetCoreMvcLocalizationModule).Assembly); |
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<AbpAspNetCoreMvcLocalizationModule>(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Get<AbpLocalizationResource>() |
|||
.AddVirtualJson("/LINGYUN/Abp/AspNetCore/Mvc/Localization/Resources"); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class GetTextByKeyInput |
|||
{ |
|||
[Required] |
|||
public string Key { get; set; } |
|||
|
|||
[Required] |
|||
public string CultureName { get; set; } |
|||
|
|||
[Required] |
|||
public string ResourceName { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class GetTextsInput |
|||
{ |
|||
[Required] |
|||
public string CultureName { get; set; } |
|||
|
|||
[Required] |
|||
public string TargetCultureName { get; set; } |
|||
|
|||
public string ResourceName { get; set; } |
|||
|
|||
public bool? OnlyNull { get; set; } |
|||
|
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public interface ILanguageAppService : IApplicationService |
|||
{ |
|||
Task<ListResultDto<LanguageDto>> GetListAsync(); |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public interface IResourceAppService : IApplicationService |
|||
{ |
|||
Task<ListResultDto<ResourceDto>> GetListAsync(); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public interface ITextAppService : IApplicationService |
|||
{ |
|||
Task<TextDto> GetByCultureKeyAsync(GetTextByKeyInput input); |
|||
|
|||
Task<ListResultDto<TextDifferenceDto>> GetListAsync(GetTextsInput input); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Authorize] |
|||
public class LanguageAppService : ApplicationService, ILanguageAppService |
|||
{ |
|||
private readonly ILanguageProvider _languageProvider; |
|||
public LanguageAppService(ILanguageProvider languageProvider) |
|||
{ |
|||
_languageProvider = languageProvider; |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<LanguageDto>> GetListAsync() |
|||
{ |
|||
var languages = await _languageProvider.GetLanguagesAsync(); |
|||
|
|||
return new ListResultDto<LanguageDto>( |
|||
languages.Select(l => new LanguageDto |
|||
{ |
|||
CultureName = l.CultureName, |
|||
UiCultureName = l.UiCultureName, |
|||
DisplayName = l.DisplayName, |
|||
FlagIcon = l.FlagIcon |
|||
}).ToList()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Area("abp")] |
|||
[RemoteService(Name = "abp")] |
|||
[Route("api/abp/localization/languages")] |
|||
public class LanguageController : AbpController, ILanguageAppService |
|||
{ |
|||
private readonly ILanguageAppService _service; |
|||
|
|||
public LanguageController(ILanguageAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<ListResultDto<LanguageDto>> GetListAsync() |
|||
{ |
|||
return _service.GetListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +1,7 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class LanguageDto : AuditedEntityDto<Guid> |
|||
public class LanguageDto |
|||
{ |
|||
public bool Enable { get; set; } |
|||
public string CultureName { get; set; } |
|||
public string UiCultureName { get; set; } |
|||
public string DisplayName { get; set; } |
|||
@ -0,0 +1,34 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.Extensions.Options; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Authorize] |
|||
public class ResourceAppService : ApplicationService, IResourceAppService |
|||
{ |
|||
private readonly AbpLocalizationOptions _localizationOptions; |
|||
|
|||
public ResourceAppService( |
|||
IOptions<AbpLocalizationOptions> localizationOptions) |
|||
{ |
|||
_localizationOptions = localizationOptions.Value; |
|||
} |
|||
|
|||
public virtual Task<ListResultDto<ResourceDto>> GetListAsync() |
|||
{ |
|||
var resources = _localizationOptions.Resources.Select(x => new ResourceDto |
|||
{ |
|||
Name = x.Value.ResourceName, |
|||
DisplayName = x.Value.ResourceName, |
|||
Description = x.Value.ResourceName, |
|||
}); |
|||
|
|||
return Task.FromResult(new ListResultDto<ResourceDto>(resources.ToList())); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Area("abp")] |
|||
[RemoteService(Name = "abp")] |
|||
[Route("api/abp/localization/resources")] |
|||
public class ResourceController : AbpController, IResourceAppService |
|||
{ |
|||
private readonly IResourceAppService _service; |
|||
|
|||
public ResourceController(IResourceAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<ListResultDto<ResourceDto>> GetListAsync() |
|||
{ |
|||
return _service.GetListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class ResourceDto |
|||
{ |
|||
public string Name { get; set; } |
|||
public string DisplayName { get; set; } |
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"Languages": "Languages", |
|||
"Resources": "Resources", |
|||
"Texts": "Texts", |
|||
"DisplayName:Key": "Key", |
|||
"DisplayName:Value": "Value", |
|||
"Description:Name": "Name", |
|||
"Description:CultureName": "Culture Name", |
|||
"Description:ResourceName": "Resource Name", |
|||
"Description:TargetCultureName": "Target Culture", |
|||
"Description:TargetValue": "Target Value", |
|||
"Description:OnlyNull": "Only Null", |
|||
"Description:Filter": "Filter", |
|||
"Description:UiCultureName": "Ui Culture Name", |
|||
"Description:DisplayName": "Display Name", |
|||
"Description:FlagIcon": "Flag Icon", |
|||
"Description:Description": "Description" |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"Languages": "语言", |
|||
"Resources": "资源", |
|||
"Texts": "文档", |
|||
"DisplayName:Key": "键名", |
|||
"DisplayName:Value": "键值", |
|||
"Description:Name": "名称", |
|||
"Description:CultureName": "文化名称", |
|||
"Description:ResourceName": "资源名称", |
|||
"Description:TargetCultureName": "目标文化", |
|||
"Description:TargetValue": "目标值", |
|||
"Description:OnlyNull": "仅限空值", |
|||
"Description:Filter": "筛选", |
|||
"Description:UiCultureName": "Ui文件名称", |
|||
"Description:DisplayName": "显示名称", |
|||
"Description:FlagIcon": "旗帜图标", |
|||
"Description:Description": "描述" |
|||
} |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.Extensions.Localization; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Authorize] |
|||
public class TextAppService : ApplicationService, ITextAppService |
|||
{ |
|||
private readonly AbpLocalizationOptions _localizationOptions; |
|||
private readonly IStringLocalizerFactory _localizerFactory; |
|||
public TextAppService( |
|||
IStringLocalizerFactory stringLocalizerFactory, |
|||
IOptions<AbpLocalizationOptions> localizationOptions) |
|||
{ |
|||
_localizerFactory = stringLocalizerFactory; |
|||
_localizationOptions = localizationOptions.Value; |
|||
} |
|||
|
|||
public virtual Task<TextDto> GetByCultureKeyAsync(GetTextByKeyInput input) |
|||
{ |
|||
var resource = _localizationOptions.Resources |
|||
.Where(l => l.Value.ResourceName.Equals(input.ResourceName)) |
|||
.Select(l => l.Value) |
|||
.FirstOrDefault(); |
|||
|
|||
IEnumerable<LocalizedString> localizedStrings = new List<LocalizedString>(); |
|||
var localizer = _localizerFactory.Create(resource.ResourceType); |
|||
|
|||
using (CultureHelper.Use(input.CultureName)) |
|||
{ |
|||
localizedStrings = localizer.GetAllStrings(true); |
|||
|
|||
var result = new TextDto |
|||
{ |
|||
Key = input.Key, |
|||
CultureName = input.CultureName, |
|||
ResourceName = input.ResourceName, |
|||
Value = localizer[input.Key]?.Value |
|||
}; |
|||
|
|||
return Task.FromResult(result); |
|||
} |
|||
} |
|||
|
|||
public virtual Task<ListResultDto<TextDifferenceDto>> GetListAsync(GetTextsInput input) |
|||
{ |
|||
var result = new List<TextDifferenceDto>(); |
|||
|
|||
if (input.ResourceName.IsNullOrWhiteSpace()) |
|||
{ |
|||
var filterResources = _localizationOptions.Resources |
|||
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Value.ResourceName.Contains(input.Filter)); |
|||
|
|||
foreach (var resource in filterResources) |
|||
{ |
|||
result.AddRange(GetTextDifferences(resource.Value, input.CultureName, input.TargetCultureName, input.Filter, input.OnlyNull)); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
var resource = _localizationOptions.Resources |
|||
.Where(l => l.Value.ResourceName.Equals(input.ResourceName)) |
|||
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Value.ResourceName.Contains(input.Filter)) |
|||
.Select(l => l.Value) |
|||
.FirstOrDefault(); |
|||
if (resource != null) |
|||
{ |
|||
result.AddRange(GetTextDifferences(resource, input.CultureName, input.TargetCultureName, input.Filter, input.OnlyNull)); |
|||
} |
|||
} |
|||
|
|||
return Task.FromResult(new ListResultDto<TextDifferenceDto>(result)); |
|||
} |
|||
|
|||
protected virtual IEnumerable<TextDifferenceDto> GetTextDifferences( |
|||
LocalizationResource resource, |
|||
string cultureName, |
|||
string targetCultureName, |
|||
string filter = null, |
|||
bool? onlyNull = null) |
|||
{ |
|||
var result = new List<TextDifferenceDto>(); |
|||
|
|||
IEnumerable<LocalizedString> localizedStrings = new List<LocalizedString>(); |
|||
IEnumerable<LocalizedString> targetLocalizedStrings = new List<LocalizedString>(); |
|||
var localizer = _localizerFactory.Create(resource.ResourceType); |
|||
|
|||
using (CultureHelper.Use(cultureName)) |
|||
{ |
|||
localizedStrings = localizer.GetAllStrings(true) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter)); |
|||
} |
|||
|
|||
if (Equals(cultureName, targetCultureName)) |
|||
{ |
|||
targetLocalizedStrings = localizedStrings; |
|||
} |
|||
else |
|||
{ |
|||
using (CultureHelper.Use(targetCultureName)) |
|||
{ |
|||
targetLocalizedStrings = localizer.GetAllStrings(true) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter)); |
|||
} |
|||
} |
|||
|
|||
foreach (var localizedString in localizedStrings) |
|||
{ |
|||
var targetLocalizedString = targetLocalizedStrings.FirstOrDefault(l => l.Name.Equals(localizedString.Name)); |
|||
if (onlyNull == true) |
|||
{ |
|||
if (targetLocalizedString == null || targetLocalizedString.Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
result.Add(new TextDifferenceDto |
|||
{ |
|||
CultureName = cultureName, |
|||
TargetCultureName = targetCultureName, |
|||
Key = localizedString.Name, |
|||
Value = localizedString.Value, |
|||
TargetValue = null, |
|||
ResourceName = resource.ResourceName |
|||
}); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
result.Add(new TextDifferenceDto |
|||
{ |
|||
CultureName = cultureName, |
|||
TargetCultureName = targetCultureName, |
|||
Key = localizedString.Name, |
|||
Value = localizedString.Value, |
|||
TargetValue = targetLocalizedString?.Value, |
|||
ResourceName = resource.ResourceName |
|||
}); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
[Area("abp")] |
|||
[RemoteService(Name = "abp")] |
|||
[Route("api/abp/localization/texts")] |
|||
public class TextController : AbpController, ITextAppService |
|||
{ |
|||
private readonly ITextAppService _service; |
|||
|
|||
public TextController(ITextAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("by-culture-key")] |
|||
public virtual Task<TextDto> GetByCultureKeyAsync(GetTextByKeyInput input) |
|||
{ |
|||
return _service.GetByCultureKeyAsync(input); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<ListResultDto<TextDifferenceDto>> GetListAsync(GetTextsInput input) |
|||
{ |
|||
return _service.GetListAsync(input); |
|||
} |
|||
} |
|||
} |
|||
@ -1,8 +1,6 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class TextDifferenceDto : EntityDto<int> |
|||
public class TextDifferenceDto |
|||
{ |
|||
public string CultureName { get; set; } |
|||
public string Key { get; set; } |
|||
@ -1,8 +1,6 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
namespace LINGYUN.Abp.AspNetCore.Mvc.Localization |
|||
{ |
|||
public class TextDto : EntityDto<int> |
|||
public class TextDto |
|||
{ |
|||
public string Key { get; set; } |
|||
public string Value { get; set; } |
|||
@ -1,25 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class CreateOrUpdateLanguageInput |
|||
{ |
|||
public virtual bool Enable { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxCultureNameLength))] |
|||
public string CultureName { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxUiCultureNameLength))] |
|||
public string UiCultureName { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxDisplayNameLength))] |
|||
public string DisplayName { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxFlagIconLength))] |
|||
public string FlagIcon { get; set; } |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class CreateOrUpdateResourceInput |
|||
{ |
|||
public bool Enable { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxDisplayNameLength))] |
|||
public string DisplayName { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxDescriptionLength))] |
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class CreateOrUpdateTextInput |
|||
{ |
|||
[DynamicStringLength(typeof(TextConsts), nameof(TextConsts.MaxValueLength))] |
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class CreateTextInput : CreateOrUpdateTextInput |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxNameLength))] |
|||
public string ResourceName { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(TextConsts), nameof(TextConsts.MaxKeyLength))] |
|||
public string Key { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxCultureNameLength))] |
|||
public string CultureName { get; set; } |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class GetLanguagesInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class GetResourcesInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class GetTextsInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxCultureNameLength))] |
|||
public string CultureName { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxCultureNameLength))] |
|||
public string TargetCultureName { get; set; } |
|||
|
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxNameLength))] |
|||
public string ResourceName { get; set; } |
|||
|
|||
public bool? OnlyNull { get; set; } |
|||
|
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public interface ILanguageAppService : |
|||
ICrudAppService< |
|||
LanguageDto, |
|||
Guid, |
|||
GetLanguagesInput, |
|||
CreateOrUpdateLanguageInput, |
|||
CreateOrUpdateLanguageInput |
|||
> |
|||
{ |
|||
Task<ListResultDto<LanguageDto>> GetAllAsync(); |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public interface IResourceAppService : |
|||
ICrudAppService< |
|||
ResourceDto, |
|||
Guid, |
|||
GetResourcesInput, |
|||
CreateOrUpdateResourceInput, |
|||
CreateOrUpdateResourceInput> |
|||
{ |
|||
Task<ListResultDto<ResourceDto>> GetAllAsync(); |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class ResourceDto : AuditedEntityDto<Guid> |
|||
{ |
|||
public bool Enable { get; set; } |
|||
public string Name { get; set; } |
|||
public string DisplayName { get; set; } |
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement; |
|||
|
|||
public class RestoreDefaultTextInput |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(ResourceConsts), nameof(ResourceConsts.MaxNameLength))] |
|||
public string ResourceName { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(TextConsts), nameof(TextConsts.MaxKeyLength))] |
|||
public string Key { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxCultureNameLength))] |
|||
public string CultureName { get; set; } |
|||
} |
|||
@ -1,6 +0,0 @@ |
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class UpdateTextInput : CreateOrUpdateTextInput |
|||
{ |
|||
} |
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
using LINGYUN.Abp.LocalizationManagement.Permissions; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class LanguageAppService : |
|||
CrudAppService< |
|||
Language, |
|||
LanguageDto, |
|||
Guid, |
|||
GetLanguagesInput, |
|||
CreateOrUpdateLanguageInput, |
|||
CreateOrUpdateLanguageInput>, |
|||
ILanguageAppService |
|||
{ |
|||
public LanguageAppService(ILanguageRepository repository) : base(repository) |
|||
{ |
|||
GetPolicyName = LocalizationManagementPermissions.Language.Default; |
|||
GetListPolicyName = LocalizationManagementPermissions.Language.Default; |
|||
CreatePolicyName = LocalizationManagementPermissions.Language.Create; |
|||
UpdatePolicyName = LocalizationManagementPermissions.Language.Update; |
|||
DeletePolicyName = LocalizationManagementPermissions.Language.Delete; |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<LanguageDto>> GetAllAsync() |
|||
{ |
|||
await CheckGetListPolicyAsync(); |
|||
|
|||
var languages = await Repository.GetListAsync(); |
|||
|
|||
return new ListResultDto<LanguageDto>( |
|||
ObjectMapper.Map<List<Language>, List<LanguageDto>>(languages)); |
|||
} |
|||
|
|||
protected override Language MapToEntity(CreateOrUpdateLanguageInput createInput) |
|||
{ |
|||
return new Language( |
|||
createInput.CultureName, |
|||
createInput.UiCultureName, |
|||
createInput.DisplayName, |
|||
createInput.FlagIcon) |
|||
{ |
|||
Enable = createInput.Enable |
|||
}; |
|||
} |
|||
|
|||
protected override void MapToEntity(CreateOrUpdateLanguageInput updateInput, Language entity) |
|||
{ |
|||
if (!string.Equals(entity.FlagIcon, updateInput.FlagIcon, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
entity.FlagIcon = updateInput.FlagIcon; |
|||
} |
|||
entity.ChangeCulture(updateInput.CultureName, updateInput.UiCultureName, updateInput.DisplayName); |
|||
entity.Enable = updateInput.Enable; |
|||
} |
|||
|
|||
protected override async Task<IQueryable<Language>> CreateFilteredQueryAsync(GetLanguagesInput input) |
|||
{ |
|||
var query = await base.CreateFilteredQueryAsync(input); |
|||
|
|||
query = query.WhereIf(!input.Filter.IsNullOrWhiteSpace(), |
|||
x => x.CultureName.Contains(input.Filter) || x.UiCultureName.Contains(input.Filter) || |
|||
x.DisplayName.Contains(input.Filter)); |
|||
|
|||
return query; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using LINGYUN.Abp.LocalizationManagement.Localization; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement; |
|||
|
|||
public abstract class LocalizationAppServiceBase : ApplicationService |
|||
{ |
|||
protected LocalizationAppServiceBase() |
|||
{ |
|||
LocalizationResource = typeof(LocalizationManagementResource); |
|||
ObjectMapperContext = typeof(AbpLocalizationManagementApplicationModule); |
|||
} |
|||
} |
|||
@ -1,15 +1,11 @@ |
|||
using AutoMapper; |
|||
|
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class LocalizationManagementApplicationMapperProfile : Profile |
|||
{ |
|||
public LocalizationManagementApplicationMapperProfile() |
|||
{ |
|||
CreateMap<Language, LanguageDto>(); |
|||
CreateMap<Resource, ResourceDto>(); |
|||
CreateMap<Text, TextDto>(); |
|||
CreateMap<TextDifference, TextDifferenceDto>(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,78 +0,0 @@ |
|||
using LINGYUN.Abp.LocalizationManagement.Permissions; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class ResourceAppService : |
|||
CrudAppService< |
|||
Resource, |
|||
ResourceDto, |
|||
Guid, |
|||
GetResourcesInput, |
|||
CreateOrUpdateResourceInput, |
|||
CreateOrUpdateResourceInput>, |
|||
IResourceAppService |
|||
{ |
|||
public ResourceAppService(IResourceRepository repository) : base(repository) |
|||
{ |
|||
GetPolicyName = LocalizationManagementPermissions.Resource.Default; |
|||
GetListPolicyName = LocalizationManagementPermissions.Resource.Default; |
|||
CreatePolicyName = LocalizationManagementPermissions.Resource.Create; |
|||
UpdatePolicyName = LocalizationManagementPermissions.Resource.Update; |
|||
DeletePolicyName = LocalizationManagementPermissions.Resource.Delete; |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<ResourceDto>> GetAllAsync() |
|||
{ |
|||
await CheckGetListPolicyAsync(); |
|||
|
|||
var resources = await Repository.GetListAsync(); |
|||
|
|||
return new ListResultDto<ResourceDto>( |
|||
ObjectMapper.Map<List<Resource>, List<ResourceDto>>(resources)); |
|||
} |
|||
|
|||
protected override Resource MapToEntity(CreateOrUpdateResourceInput createInput) |
|||
{ |
|||
return new Resource( |
|||
createInput.Name, |
|||
createInput.DisplayName, |
|||
createInput.Description) |
|||
{ |
|||
Enable = createInput.Enable |
|||
}; |
|||
} |
|||
|
|||
protected override void MapToEntity(CreateOrUpdateResourceInput updateInput, Resource entity) |
|||
{ |
|||
if (!string.Equals(entity.Name, updateInput.Name, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
entity.Name = updateInput.Name; |
|||
} |
|||
if (!string.Equals(entity.DisplayName, updateInput.DisplayName, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
entity.DisplayName = updateInput.DisplayName; |
|||
} |
|||
if (!string.Equals(entity.Description, updateInput.Description, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
entity.Description = updateInput.Description; |
|||
} |
|||
entity.Enable = updateInput.Enable; |
|||
} |
|||
|
|||
protected override async Task<IQueryable<Resource>> CreateFilteredQueryAsync(GetResourcesInput input) |
|||
{ |
|||
var query = await base.CreateFilteredQueryAsync(input); |
|||
|
|||
query = query.WhereIf(!input.Filter.IsNullOrWhiteSpace(), |
|||
x => x.Name.Contains(input.Filter) || x.DisplayName.Contains(input.Filter)); |
|||
|
|||
return query; |
|||
} |
|||
} |
|||
} |
|||
@ -1,73 +1,55 @@ |
|||
using LINGYUN.Abp.LocalizationManagement.Permissions; |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class TextAppService : |
|||
CrudAppService< |
|||
Text, |
|||
TextDto, |
|||
TextDifferenceDto, |
|||
int, |
|||
GetTextsInput, |
|||
CreateTextInput, |
|||
UpdateTextInput>, |
|||
ITextAppService |
|||
[Authorize(LocalizationManagementPermissions.Text.Default)] |
|||
public class TextAppService : LocalizationAppServiceBase, ITextAppService |
|||
{ |
|||
private readonly ITextRepository _textRepository; |
|||
public TextAppService(ITextRepository repository) : base(repository) |
|||
public TextAppService(ITextRepository repository) |
|||
{ |
|||
_textRepository = repository; |
|||
|
|||
GetPolicyName = LocalizationManagementPermissions.Text.Default; |
|||
GetListPolicyName = LocalizationManagementPermissions.Text.Default; |
|||
CreatePolicyName = LocalizationManagementPermissions.Text.Create; |
|||
UpdatePolicyName = LocalizationManagementPermissions.Text.Update; |
|||
DeletePolicyName = LocalizationManagementPermissions.Text.Delete; |
|||
} |
|||
|
|||
public virtual async Task<TextDto> GetByCultureKeyAsync(GetTextByKeyInput input) |
|||
{ |
|||
await CheckGetPolicyAsync(); |
|||
|
|||
var text = await _textRepository.GetByCultureKeyAsync( |
|||
input.ResourceName, input.CultureName, input.Key); |
|||
|
|||
return await MapToGetOutputDtoAsync(text); |
|||
public async virtual Task SetTextAsync(SetTextInput input) |
|||
{ |
|||
var text = await _textRepository.GetByCultureKeyAsync(input.ResourceName, input.CultureName, input.Key); |
|||
if (text == null) |
|||
{ |
|||
await AuthorizationService.CheckAsync(LocalizationManagementPermissions.Text.Create); |
|||
|
|||
text = new Text( |
|||
input.ResourceName, |
|||
input.CultureName, |
|||
input.Key, |
|||
input.Value); |
|||
|
|||
await _textRepository.InsertAsync(text); |
|||
} |
|||
else |
|||
{ |
|||
await AuthorizationService.CheckAsync(LocalizationManagementPermissions.Text.Update); |
|||
|
|||
text.SetValue(input.Value); |
|||
|
|||
await _textRepository.UpdateAsync(text); |
|||
} |
|||
|
|||
await CurrentUnitOfWork.SaveChangesAsync(); |
|||
} |
|||
|
|||
public override async Task<PagedResultDto<TextDifferenceDto>> GetListAsync(GetTextsInput input) |
|||
{ |
|||
await CheckGetListPolicyAsync(); |
|||
|
|||
var count = await _textRepository.GetDifferenceCountAsync( |
|||
input.CultureName, input.TargetCultureName, |
|||
input.ResourceName, input.OnlyNull, input.Filter); |
|||
|
|||
var texts = await _textRepository.GetDifferencePagedListAsync( |
|||
input.CultureName, input.TargetCultureName, |
|||
input.ResourceName, input.OnlyNull, input.Filter, |
|||
input.Sorting, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<TextDifferenceDto>(count, |
|||
ObjectMapper.Map<List<TextDifference>, List<TextDifferenceDto>>(texts)); |
|||
} |
|||
|
|||
protected override Text MapToEntity(CreateTextInput createInput) |
|||
{ |
|||
return new Text( |
|||
createInput.ResourceName, |
|||
createInput.CultureName, |
|||
createInput.Key, |
|||
createInput.Value); |
|||
} |
|||
|
|||
protected override void MapToEntity(UpdateTextInput updateInput, Text entity) |
|||
{ |
|||
entity.SetValue(updateInput.Value); |
|||
[Authorize(LocalizationManagementPermissions.Text.Delete)] |
|||
public async virtual Task RestoreToDefaultAsync(RestoreDefaultTextInput input) |
|||
{ |
|||
var text = await _textRepository.GetByCultureKeyAsync(input.ResourceName, input.CultureName, input.Key); |
|||
if (text != null) |
|||
{ |
|||
await _textRepository.DeleteAsync(text); |
|||
|
|||
await CurrentUnitOfWork.SaveChangesAsync(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,62 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
[RemoteService(Name = LocalizationRemoteServiceConsts.RemoteServiceName)] |
|||
[Area("localization")] |
|||
[Route("api/localization/languages")] |
|||
public class LanguageController : AbpController, ILanguageAppService |
|||
{ |
|||
private readonly ILanguageAppService _service; |
|||
|
|||
public LanguageController(ILanguageAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpPost] |
|||
public virtual async Task<LanguageDto> CreateAsync(CreateOrUpdateLanguageInput input) |
|||
{ |
|||
return await _service.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpDelete] |
|||
[Route("{id}")] |
|||
public virtual async Task DeleteAsync(Guid id) |
|||
{ |
|||
await _service.DeleteAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("all")] |
|||
public virtual async Task<ListResultDto<LanguageDto>> GetAllAsync() |
|||
{ |
|||
return await _service.GetAllAsync(); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("{id}")] |
|||
public virtual async Task<LanguageDto> GetAsync(Guid id) |
|||
{ |
|||
return await _service.GetAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual async Task<PagedResultDto<LanguageDto>> GetListAsync(GetLanguagesInput input) |
|||
{ |
|||
return await _service.GetListAsync(input); |
|||
} |
|||
|
|||
[HttpPut] |
|||
[Route("{id}")] |
|||
public virtual async Task<LanguageDto> UpdateAsync(Guid id, CreateOrUpdateLanguageInput input) |
|||
{ |
|||
return await _service.UpdateAsync(id, input); |
|||
} |
|||
} |
|||
} |
|||
@ -1,62 +0,0 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
[RemoteService(Name = LocalizationRemoteServiceConsts.RemoteServiceName)] |
|||
[Area("localization")] |
|||
[Route("api/localization/resources")] |
|||
public class ResourceController : AbpController, IResourceAppService |
|||
{ |
|||
private readonly IResourceAppService _service; |
|||
|
|||
public ResourceController(IResourceAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpPost] |
|||
public virtual async Task<ResourceDto> CreateAsync(CreateOrUpdateResourceInput input) |
|||
{ |
|||
return await _service.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpDelete] |
|||
[Route("{id}")] |
|||
public virtual async Task DeleteAsync(Guid id) |
|||
{ |
|||
await _service.DeleteAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("all")] |
|||
public virtual async Task<ListResultDto<ResourceDto>> GetAllAsync() |
|||
{ |
|||
return await _service.GetAllAsync(); |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("{id}")] |
|||
public virtual async Task<ResourceDto> GetAsync(Guid id) |
|||
{ |
|||
return await _service.GetAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual async Task<PagedResultDto<ResourceDto>> GetListAsync(GetResourcesInput input) |
|||
{ |
|||
return await _service.GetListAsync(input); |
|||
} |
|||
|
|||
[HttpPut] |
|||
[Route("{id}")] |
|||
public virtual async Task<ResourceDto> UpdateAsync(Guid id, CreateOrUpdateResourceInput input) |
|||
{ |
|||
return await _service.UpdateAsync(id, input); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue