Revise IExternalLocalizationStore usage.

pull/13845/head
Halil İbrahim Kalkan 3 years ago
parent 95f6b288a8
commit f35e790360

@ -215,10 +215,21 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync());
foreach (var resource in _localizationOptions.Resources.Values)
var resourceNames = _localizationOptions.Resources.Values.Select(x => x.ResourceName);
if (_externalLocalizationOptions.GetFromExternalStore)
{
var externalResourceNames = await LazyServiceProvider
.LazyGetRequiredService<IExternalLocalizationStore>()
.GetResourceNamesAsync();
resourceNames = resourceNames.Union(externalResourceNames);
}
foreach (var resourceName in resourceNames)
{
var dictionary = new Dictionary<string, string>();
var localizer = StringLocalizerFactory.CreateByResourceNameOrNull(resource.ResourceName);
var localizer = StringLocalizerFactory.CreateByResourceNameOrNull(resourceName);
if (localizer != null)
{
foreach (var localizedString in localizer.GetAllStrings())
@ -227,20 +238,7 @@ public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApp
}
}
localizationConfig.Values[resource.ResourceName] = dictionary;
}
if (_externalLocalizationOptions.GetFromExternalStore)
{
var distributedLocalizationData = await this
.LazyServiceProvider
.LazyGetRequiredService<IExternalLocalizationStore>()
.GetAsync();
foreach (var resource in distributedLocalizationData.Resources)
{
localizationConfig.Values[resource.ResourceName] = resource.Texts;
}
localizationConfig.Values[resourceName] = dictionary;
}
localizationConfig.CurrentCulture = GetCurrentCultureInfo();

@ -1,18 +0,0 @@
using System.Collections.Generic;
namespace Volo.Abp.Localization.External;
public class ExternalLocalizationData
{
public List<ExternalLocalizationResourceData> Resources { get; }
public ExternalLocalizationData()
{
Resources = new();
}
public ExternalLocalizationData(List<ExternalLocalizationResourceData> resources)
{
Resources = Check.NotNull(resources, nameof(resources));
}
}

@ -1,22 +0,0 @@
using System.Collections.Generic;
namespace Volo.Abp.Localization.External;
public class ExternalLocalizationResourceData
{
public string ResourceName { get; }
public Dictionary<string, string> Texts { get; }
public ExternalLocalizationResourceData(string resourceName)
{
ResourceName = Check.NotNullOrWhiteSpace(resourceName, nameof(resourceName));
Texts = new();
}
public ExternalLocalizationResourceData(string resourceName, Dictionary<string, string> texts)
{
ResourceName = Check.NotNullOrWhiteSpace(resourceName, nameof(resourceName));
Texts = Check.NotNull(texts, nameof(texts));
}
}

@ -10,7 +10,5 @@ public interface IExternalLocalizationStore
[CanBeNull]
LocalizationResourceBase GetResourceOrNull([NotNull] string resourceName);
Task<ExternalLocalizationData> GetAsync();
Task<string[]> GetResourceNames();
Task<string[]> GetResourceNamesAsync();
}

@ -6,8 +6,6 @@ namespace Volo.Abp.Localization.External;
public class NullExternalLocalizationStore : IExternalLocalizationStore, ISingletonDependency
{
private readonly ExternalLocalizationData _data = new();
public Task SaveAsync()
{
return Task.CompletedTask;
@ -18,12 +16,7 @@ public class NullExternalLocalizationStore : IExternalLocalizationStore, ISingle
return null;
}
public Task<ExternalLocalizationData> GetAsync()
{
return Task.FromResult(_data);
}
public Task<string[]> GetResourceNames()
public Task<string[]> GetResourceNamesAsync()
{
return Task.FromResult(Array.Empty<string>());
}

Loading…
Cancel
Save