- 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)
-
0
hi
You can get language settings after changing to the tenant.
using (CurrentTenant.Change(tenantId)) { var defaultLanguage = await settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); }
-
0
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
-
0
hi
The
LocalizationSettingNames.DefaultLanguage
is a setting so you can change via https://docs.abp.io/en/abp/latest/Settingshow I can use it to translate string
https://docs.abp.io/en/abp/latest/Localization
-
0
hi
The
LocalizationSettingNames.DefaultLanguage
is a setting so you can change via https://docs.abp.io/en/abp/latest/Settingshow 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..
-
0
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() }
-
0
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.
-
0
sorry,
var defaultLanguage = await _settingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); var (cultureName, uiCultureName) = LocalizationSettingHelper.ParseLanguageSetting(defaultLanguage); using (CultureHelper.Use(CultureInfo.GetCultureInfo(cultureName))) { GenerateViolationReport() }
-
0
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