2025-05-06 06:45:49 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
|
using Volo.Abp.Localization;
|
|
|
|
|
|
|
2025-11-11 19:49:52 +00:00
|
|
|
|
namespace Erp.Languages.Localization;
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
|
|
|
|
|
public class DatabaseLocalizationResourceContributor : ILocalizationResourceContributor
|
|
|
|
|
|
{
|
|
|
|
|
|
private LocalizationResourceBase _resource;
|
|
|
|
|
|
private IDatabaseResourceLocalizer _databaseResourceLocalizer;
|
|
|
|
|
|
private ILanguageProvider _languageProvider;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsDynamic => false;
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(LocalizationResourceInitializationContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
_resource = context.Resource;
|
|
|
|
|
|
_databaseResourceLocalizer = context.ServiceProvider.GetRequiredService<IDatabaseResourceLocalizer>();
|
|
|
|
|
|
_languageProvider = context.ServiceProvider.GetRequiredService<ILanguageProvider>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LocalizedString GetOrNull(string cultureName, string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _databaseResourceLocalizer.GetOrNull(_resource, cultureName, name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task FillAsync(string cultureName, Dictionary<string, LocalizedString> dictionary)
|
|
|
|
|
|
{
|
|
|
|
|
|
await _databaseResourceLocalizer.FillAsync(_resource, cultureName, dictionary);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Fill(string cultureName, Dictionary<string, LocalizedString> dictionary)
|
|
|
|
|
|
{
|
|
|
|
|
|
_databaseResourceLocalizer.Fill(_resource, cultureName, dictionary);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<string>> GetSupportedCulturesAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
var langs = await _languageProvider.GetLanguagesAsync();
|
|
|
|
|
|
return langs.Select(a => a.CultureName).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-11 19:49:52 +00:00
|
|
|
|
|