Open Closed

Language Text changes to be platform wide #8778


User avatar
0
Bryan-EDV created
  • ABP Framework version: v9.0.2

  • UI Type: Angular / MVC

  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)

  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

  • Exception message and full stack trace:

  • Steps to reproduce the issue:

Hi, we noticed that language texts have to be changed in each tenant.

Is there a way to set it platform wide? ie. changing the language text in Host will be applicable for all Tenants.

Thanks.


5 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    For this, you can override the following CreateFilterExpression method in the MyAppDbContext class in the MyApp.EntityFrameworkCore project of your application as follows:

    protected override Expression<Func<TEntity, bool>>? CreateFilterExpression<TEntity>(ModelBuilder modelBuilder)
        {
            Expression<Func<TEntity, bool>> expression = null;
    
            if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
            {
                var softDeleteColumnName = modelBuilder.Entity<TEntity>().Metadata.FindProperty(nameof(ISoftDelete.IsDeleted))?.GetColumnName() ?? "IsDeleted";
                expression = e => !IsSoftDeleteFilterEnabled || !EF.Property<bool>(e, softDeleteColumnName);
                if (UseDbFunction())
                {
                    expression = e => AbpEfCoreDataFilterDbFunctionMethods.SoftDeleteFilter(((ISoftDelete)e).IsDeleted, true);
                    modelBuilder.ConfigureSoftDeleteDbFunction(AbpEfCoreDataFilterDbFunctionMethods.SoftDeleteFilterMethodInfo, this.GetService<AbpEfCoreCurrentDbContext>());
                }
            }
    
            if (typeof(IMultiTenant).IsAssignableFrom(typeof(TEntity)) && typeof(TEntity) != typeof(LanguageText))
            {
                var multiTenantColumnName = modelBuilder.Entity<TEntity>().Metadata.FindProperty(nameof(IMultiTenant.TenantId))?.GetColumnName() ?? "TenantId";
                Expression<Func<TEntity, bool>> multiTenantFilter = e => !IsMultiTenantFilterEnabled || EF.Property<Guid>(e, multiTenantColumnName) == CurrentTenantId;
                if (UseDbFunction())
                {
                    multiTenantFilter = e => AbpEfCoreDataFilterDbFunctionMethods.MultiTenantFilter(((IMultiTenant)e).TenantId, CurrentTenantId, true);
                    modelBuilder.ConfigureMultiTenantDbFunction(AbpEfCoreDataFilterDbFunctionMethods.MultiTenantFilterMethodInfo, this.GetService<AbpEfCoreCurrentDbContext>());
                }
                expression = expression == null ? multiTenantFilter : QueryFilterExpressionHelper.CombineExpressions(expression, multiTenantFilter);
            }
            
            return expression;
        }
    

    Then you need to replace the LanguageManagementDbContext from DI Container as in the picture below:

    Screenshot 2025-02-11 at 12.53.47.png

  • User Avatar
    0
    Bryan-EDV created

    Hi berkansasmaz,

    I've done the following as you mentioned, however the text in tenants are still different from what' we've set in host

    Changed host text (Recommended Realplays --changed to--> Your Recommended Realplays)
    image.png
    image.png

    old default value in en.json
    image.png

    However, despite implementing code you provided, the tenant still sees different (old) text:
    image.png

  • User Avatar
    0
    Bryan-EDV created

    After some testing, i did notice that language texts that do not have a base value in that language will cascade fine.
    image.png

    I set value of Deutsch translation to "Guten Tag" in host, that seems to cascade to tenant fine. There is no value for HomePage:Title2 in the de-DE.json

    • When text is defined in en.json, it does not cascade down to tenant (even when updated by host)

    • When text is not defined in languagexxx.json file, and updated in GUI by host, it will cascade to tenants

  • User Avatar
    0
    Bryan-EDV created

    Hi any response on this? thanks

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    Looks interesting, please share your solution via email (to support@abp.io with ticket number) if possible, so we can resolve your issue faster.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 20, 2025, 18:00