mirror of https://github.com/abpframework/abp.git
committed by
GitHub
5 changed files with 136 additions and 0 deletions
@ -0,0 +1,44 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Localization.TestResources.External; |
||||
|
|
||||
|
public class TestExternalLocalizationContributor : ILocalizationResourceContributor |
||||
|
{ |
||||
|
public bool IsDynamic => true; |
||||
|
|
||||
|
private string ResourceName { get; set; } |
||||
|
|
||||
|
public void Initialize(LocalizationResourceInitializationContext context) |
||||
|
{ |
||||
|
ResourceName = context.Resource.ResourceName; |
||||
|
} |
||||
|
|
||||
|
public LocalizedString GetOrNull(string cultureName, string name) |
||||
|
{ |
||||
|
switch (ResourceName) |
||||
|
{ |
||||
|
case TestExternalLocalizationStore.TestExternalResourceNames.ExternalResource1: |
||||
|
case TestExternalLocalizationStore.TestExternalResourceNames.ExternalResource2: |
||||
|
return new LocalizedString(name, name ); |
||||
|
default: |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void Fill(string cultureName, Dictionary<string, LocalizedString> dictionary) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public Task FillAsync(string cultureName, Dictionary<string, LocalizedString> dictionary) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
public Task<IEnumerable<string>> GetSupportedCulturesAsync() |
||||
|
{ |
||||
|
return Task.FromResult(new List<string>().AsEnumerable()); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Localization.External; |
||||
|
|
||||
|
namespace Volo.Abp.Localization.TestResources.External; |
||||
|
|
||||
|
public class TestExternalLocalizationStore : IExternalLocalizationStore, ITransientDependency |
||||
|
{ |
||||
|
private readonly IDictionary<string, LocalizationResourceBase> _resources = new LocalizationResourceDictionary(); |
||||
|
|
||||
|
public LocalizationResourceBase GetResourceOrNull(string resourceName) |
||||
|
{ |
||||
|
return GetOrCreateResource(resourceName); |
||||
|
} |
||||
|
|
||||
|
public Task<LocalizationResourceBase> GetResourceOrNullAsync(string resourceName) |
||||
|
{ |
||||
|
return Task.FromResult(GetOrCreateResource(resourceName)); |
||||
|
} |
||||
|
|
||||
|
public Task<string[]> GetResourceNamesAsync() |
||||
|
{ |
||||
|
return Task.FromResult(new []{TestExternalResourceNames.ExternalResource1, TestExternalResourceNames.ExternalResource2}); |
||||
|
} |
||||
|
|
||||
|
public async Task<LocalizationResourceBase[]> GetResourcesAsync() |
||||
|
{ |
||||
|
var resourceNames = await GetResourceNamesAsync(); |
||||
|
return resourceNames.Select(GetResourceOrNull).ToArray(); |
||||
|
} |
||||
|
|
||||
|
private LocalizationResourceBase GetOrCreateResource(string resourceName) |
||||
|
{ |
||||
|
if(resourceName != TestExternalResourceNames.ExternalResource1 && resourceName != TestExternalResourceNames.ExternalResource2) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return _resources.GetOrAdd(resourceName, name => new NonTypedLocalizationResource(name)); |
||||
|
} |
||||
|
|
||||
|
public class TestExternalResourceNames |
||||
|
{ |
||||
|
public const string ExternalResource1 = "TestExternalResource1"; |
||||
|
|
||||
|
public const string ExternalResource2 = "TestExternalResource2"; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue