Open Closed

set specified language for the tenant in the backgroundJob #3636


User avatar
0
yasin.hallak.89@gmail.com created
  • ABP Framework version: v5.0.0
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Language in backgrounJob "Hangfire": Hi there ....

I want to set the specified language for the tenant in the backgroundJob Hangfire

example: if the tenant is arabic language I want to set language arabic ...

How I can implementation that please ...


8 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can get language settings after changing to the tenant.

    using (CurrentTenant.Change(tenantId))
    {
        var defaultLanguage = await settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);
    }
    
  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    var defaultLanguage = await settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);

    thanks ... what is the next step ..

    how I can set DefaultLanguage in my code

    how I can use it to translate string

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The LocalizationSettingNames.DefaultLanguage is a setting so you can change via https://docs.abp.io/en/abp/latest/Settings

    how I can use it to translate string

    https://docs.abp.io/en/abp/latest/Localization

  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    hi

    The LocalizationSettingNames.DefaultLanguage is a setting so you can change via https://docs.abp.io/en/abp/latest/Settings

    how I can use it to translate string

    https://docs.abp.io/en/abp/latest/Localization

    Hi bro ..

    this is Excution method for backgrounJob Hangifire

    public async Task Excute()
            {
                var tenants = await _tenantRepository.GetListAsync();
                foreach (var tenant in tenants)
                {
                   
                    using (_currentTenant.Change(tenant.Id))
                    {
                        // get defaultLanguage for this tenant
                        var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);
    
                        // here I want to set defaultLanguage to use it in GenerateViolationReport() method 
                        //...
                        //...
                        
                        var absenceAssignmentEmployees = await GetAbsenceAssignmentEmployees();
    
                        var toBeReported = await GenerateAbsenceReport(absenceAssignmentEmployees);
                        if (toBeReported.Any())
                        {
                            await _absenceRepository.InsertManyAsync(toBeReported, autoSave: true);
                            var absenceIds = toBeReported.Select(absence => absence.Id).ToList();
                            // get absences with related data
                            var absences = await _absenceRepository.GetAbsencesByAbsenceIdsWithDetailsAsync(absenceIds);
                            //TODO EntityLogs
    
                            var violations = await GenerateViolationReport(absences);
                            if (violations.Any())
                            {
                                await _violationRepository.InsertManyAsync(violations, autoSave: true);
                                //TODO EntityLogs
                            }
                        }
                    }
                }
            }
    

    I read this documnet https://docs.abp.io/en/abp/latest/Settings and saw this way :

    public class MySettingDefinitionProvider : SettingDefinitionProvider
    {
        public override void Define(ISettingDefinitionContext context)
        {
            var smtpHost = context.GetOrNull("Abp.Mailing.Smtp.Host");
            if (smtpHost != null)
            {
                smtpHost.DefaultValue = "mail.mydomain.com";
                smtpHost.DisplayName = 
                    new LocalizableString(
                        typeof(MyLocalizationResource),
                        "SmtpServer_DisplayName"
                    );
            }
        }
    }
    

    but I did not know way to set DefaultLanguage from My code

    can you help me Pls ....

    Thanx..

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    here I want to set defaultLanguage to use it in GenerateViolationReport() method

    hi

    You can switch the current culture

    // get defaultLanguage for this tenant
    var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);
    
    // here I want to set defaultLanguage to use it in GenerateViolationReport() method 
    
    using (CultureHelper.Use(CultureInfo.GetCultureInfo(defaultLanguage)))
    {
        GenerateViolationReport()
    }
    
  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    hi

    here I want to set defaultLanguage to use it in GenerateViolationReport() method

    hi

    You can switch the current culture

    // get defaultLanguage for this tenant 
    var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); 
     
    // here I want to set defaultLanguage to use it in GenerateViolationReport() method  
     
    using (CultureHelper.Use(CultureInfo.GetCultureInfo(defaultLanguage))) 
    { 
        GenerateViolationReport() 
    } 
    

    Hi bro .. I am sorry it gave me this error

    System.Globalization.CultureNotFoundException: Culture is not supported. (Parameter 'name') ar;ar is an invalid culture identifier.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    sorry,

    
    var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); 
    var (cultureName, uiCultureName) = LocalizationSettingHelper.ParseLanguageSetting(defaultLanguage);
    using (CultureHelper.Use(CultureInfo.GetCultureInfo(cultureName))) 
    { 
        GenerateViolationReport() 
    } 
    
  • User Avatar
    0
    yasin.hallak.89@gmail.com created

    sorry,

     
    var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage);  
    var (cultureName, uiCultureName) = LocalizationSettingHelper.ParseLanguageSetting(defaultLanguage); 
    using (CultureHelper.Use(CultureInfo.GetCultureInfo(cultureName)))  
    {  
        GenerateViolationReport()  
    }  
    

    Now it work well Thanx

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15