-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41dba35
commit e21cf5c
Showing
25 changed files
with
464 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 19 additions & 77 deletions
96
framework/src/Volo.Abp.AutoMapper/AutoMapper/AbpAutoMapperMultiLingualDtoExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Volo.Abp.Domain.Entities; | ||
using Volo.Abp.Localization; | ||
using Volo.Abp.MultiLingualObject; | ||
using Volo.Abp.Settings; | ||
using Volo.Abp.Threading; | ||
|
||
namespace AutoMapper | ||
{ | ||
public static class AbpAutoMapperMultiLingualDtoExtensions | ||
{ | ||
public static CreateMultiLingualMapResult<TMultiLingualEntity, TTranslation, TDestination> CreateMultLingualMap< | ||
TMultiLingualEntity, | ||
public static CreateMultiLingualMapResult<TSource, TTranslation, TDestination> MapMultiLingual<TSource, | ||
TTranslation, TDestination>( | ||
this Profile profile, | ||
ISettingProvider serviceProvider, | ||
this IMappingExpression<TSource, TDestination> mappingExpression, | ||
Profile profile, | ||
ISettingProvider provider, | ||
bool fallbackToParentCultures = false) | ||
where TMultiLingualEntity : class, IMultiLingualEntity<TTranslation> | ||
where TTranslation : class, IEntityTranslation | ||
where TDestination : class | ||
where TSource : IHasMultiLingual<TTranslation> | ||
where TTranslation : class, IMultiLingualTranslation | ||
{ | ||
return new CreateMultiLingualMapResult<TMultiLingualEntity, TTranslation, TDestination> | ||
return new CreateMultiLingualMapResult<TSource, TTranslation, TDestination> | ||
{ | ||
TranslationMap = profile.CreateMap<TTranslation, TDestination>(), | ||
EntityMap = profile.CreateMap<TMultiLingualEntity, TDestination>().BeforeMap( | ||
(source, destination, context) => | ||
{ | ||
if (source.Translations == null || !source.Translations.Any()) | ||
{ | ||
return; | ||
} | ||
var translation = | ||
source.Translations.FirstOrDefault(pt => pt.Language == CultureInfo.CurrentUICulture.Name); | ||
if (translation != null) | ||
{ | ||
context.Mapper.Map(translation, destination); | ||
return; | ||
} | ||
if (fallbackToParentCultures) | ||
{ | ||
translation = | ||
GeTranslationBasedOnCulturalRecursive<TMultiLingualEntity, TTranslation>( | ||
CultureInfo.CurrentUICulture.Parent, source.Translations, 0); | ||
if (translation != null) | ||
{ | ||
context.Mapper.Map(translation, destination); | ||
return; | ||
} | ||
} | ||
|
||
var defaultLanguage = AsyncHelper.RunSync(() => | ||
serviceProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage)); | ||
EntityMap = mappingExpression.BeforeMap((source, destination, context) => | ||
{ | ||
var translation = source.GetMultiLingualTranslation(provider, fallbackToParentCultures); | ||
translation = source.Translations.FirstOrDefault(pt => pt.Language == defaultLanguage); | ||
if (translation != null) | ||
{ | ||
context.Mapper.Map(translation, destination); | ||
return; | ||
} | ||
translation = source.Translations.FirstOrDefault(); | ||
if (translation != null) | ||
{ | ||
context.Mapper.Map(translation, destination); | ||
} | ||
}) | ||
if (translation != null) | ||
{ | ||
context.Mapper.Map(translation, destination); | ||
} | ||
}) | ||
}; | ||
} | ||
|
||
private const int MaxCultureFallbackDepth = 5; | ||
|
||
private static TTranslation GeTranslationBasedOnCulturalRecursive<TMultiLingualEntity, TTranslation>( | ||
CultureInfo culture, ICollection<TTranslation> translations, int currentDepth) | ||
where TTranslation : class, IEntityTranslation | ||
{ | ||
if (culture == null || culture.Name.IsNullOrWhiteSpace() || translations.IsNullOrEmpty() || | ||
currentDepth > MaxCultureFallbackDepth) | ||
{ | ||
return null; | ||
} | ||
|
||
var translation = translations.FirstOrDefault(pt => | ||
pt.Language.Equals(culture.Name, StringComparison.OrdinalIgnoreCase)); | ||
return translation ?? | ||
GeTranslationBasedOnCulturalRecursive<TMultiLingualEntity, TTranslation>(culture.Parent, | ||
translations, currentDepth + 1); | ||
} | ||
} | ||
|
||
public class CreateMultiLingualMapResult<TMultiLingualEntity, TTranslation, TDestination> | ||
public class CreateMultiLingualMapResult<TMultiLingual, TTranslation, TDestination> | ||
{ | ||
public IMappingExpression<TTranslation, TDestination> TranslationMap { get; set; } | ||
|
||
public IMappingExpression<TMultiLingualEntity, TDestination> EntityMap { get; set; } | ||
public IMappingExpression<TMultiLingual, TDestination> EntityMap { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/IEntityTranslation.cs
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/IMultiLingualEntity.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
15 changes: 15 additions & 0 deletions
15
framework/src/Volo.Abp.MultiLingualObject/Volo.Abp.MultiLingualObject.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
11 changes: 11 additions & 0 deletions
11
...rc/Volo.Abp.MultiLingualObject/Volo/Abp/MultiLingualObject/AbpMultiLingualObjectModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Volo.Abp.Localization; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace Volo.Abp.MultiLingualObject | ||
{ | ||
[DependsOn( | ||
typeof(AbpLocalizationModule))] | ||
public class AbpMultiLingualObjectModule : AbpModule | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
framework/src/Volo.Abp.MultiLingualObject/Volo/Abp/MultiLingualObject/IHasMultiLingual.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Volo.Abp.MultiLingualObject | ||
{ | ||
public interface IHasMultiLingual<TTranslation> | ||
where TTranslation : class, IMultiLingualTranslation | ||
{ | ||
ICollection<TTranslation> Translations { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...k/src/Volo.Abp.MultiLingualObject/Volo/Abp/MultiLingualObject/IMultiLingualTranslation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Volo.Abp.MultiLingualObject | ||
{ | ||
public interface IMultiLingualTranslation | ||
{ | ||
string Language { get; set; } | ||
} | ||
|
||
public interface IMultiLingualTranslation<T, TPrimaryKeyOfMultiLingualObject> : IMultiLingualTranslation | ||
where T : class | ||
{ | ||
T Core { get; set; } | ||
|
||
TPrimaryKeyOfMultiLingualObject CoreId { get; set; } | ||
} | ||
} |
Oops, something went wrong.