Hello,
We are working on a Multi-tenant application (ASP.NET core + Angular).
It appears that translations( table abplanguagetexts ) takes the tenant into account which would lead to different translations for different tenants (for a same language).
I would like to know how to achieve one translation for all tenant in a language. For example for ABPUI:ADDROLE, I want to add only a row in French with "Ajouter rôle" as a value instead of 1 row per tenant for this ABPUI:ADDROLE key.
To say it differently I would like the translation engine NOT to check the tenant when looking for a translation.
Is there a way to do this ?
Thanks
Thomas
- ABP Framework version: 4.3
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:
2 Answer(s)
-
2
hi
You can try to switch to Host side in the
DynamicResourceLocalizer
subclass.using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.LanguageManagement; using Volo.Abp.Localization; using Volo.Abp.MultiTenancy; namespace MyCompanyName.MyProjectName.Web { [Dependency(ReplaceServices = true)] public class MyDynamicResourceLocalizer : DynamicResourceLocalizer { public MyDynamicResourceLocalizer( IServiceScopeFactory serviceScopeFactory, IDistributedCache<LanguageTextCacheItem> cache) : base(serviceScopeFactory, cache) { } protected override LanguageTextCacheItem CreateCacheItem(LocalizationResource resource, string cultureName) { var cacheItem = new LanguageTextCacheItem(); using (var scope = ServiceScopeFactory.CreateScope()) { var currentTenant = scope.ServiceProvider.GetRequiredService<ICurrentTenant>(); using (currentTenant.Change(null)) { var texts = scope.ServiceProvider .GetRequiredService<ILanguageTextRepository>() .GetList(resource.ResourceName, cultureName); foreach (var text in texts) { cacheItem.Dictionary[text.Name] = text.Value; } } } return cacheItem; } } }
-
0
Hello Maliming,
Thank you for your quick reply, your solution works very nicely !
( I just had to replace the resource.ResourceName with the name of the resource I want to target, for exampel AbpIdentity)
Best Regards
Thomas