You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
3 years ago
|
using Sanhe.Abp.Localization.Dynamic;
|
||
|
using System;
|
||
|
using System.Linq;
|
||
|
|
||
|
namespace Volo.Abp.Localization
|
||
|
{
|
||
|
public static class LocalizationResourceDictionaryExtensions
|
||
|
{
|
||
|
public static LocalizationResourceDictionary AddDynamic(
|
||
|
this LocalizationResourceDictionary resources,
|
||
|
params Type[] ignoreResourceTypes)
|
||
|
{
|
||
|
foreach (var resource in resources)
|
||
|
{
|
||
|
if (ShouldIgnoreType(resource.Key, ignoreResourceTypes))
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
if (ShouldIgnoreType(resource.Value))
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
resource.Value.AddDynamic();
|
||
|
}
|
||
|
return resources;
|
||
|
}
|
||
|
|
||
|
private static bool ShouldIgnoreType(Type resourceType, params Type[] ignoreResourceTypes)
|
||
|
{
|
||
|
if (ignoreResourceTypes == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
return ignoreResourceTypes.Any(x => x == resourceType);
|
||
|
}
|
||
|
|
||
|
private static bool ShouldIgnoreType(LocalizationResource resource)
|
||
|
{
|
||
|
return resource.Contributors.Exists(x => x is DynamicLocalizationResourceContributor);
|
||
|
}
|
||
|
}
|
||
|
}
|