protected override async Task OnInitializedAsync() { try { Console.WriteLine("-----------------------------------------------"); var lang = await LanguageProvider.GetLanguagesAsync(); Console.WriteLine(CultureInfo.CurrentCulture.Name); var AbpLocalizationOptions = abpLocalizationOptions.Value; Type resourceType = typeof(ContabilidadResource); var resource = AbpLocalizationOptions.Resources.GetOrDefault(resourceType); Console.WriteLine((resource == null).ToString(), resource); var Localizer = InnerFactory.Create(resourceType); Console.WriteLine((Localizer == null).ToString(), Localizer); Console.WriteLine(Localizer.GetString("LongWelcomeMessage")); var all = Localizer.GetAllStrings(); Console.WriteLine($"{all.Count()} {all.First().Name}", all); Console.WriteLine($"Contributors : {resource.Contributors.Count}"); Console.WriteLine("-----------------------------------------------"); } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } }
protected virtual async Task <ApplicationLocalizationConfigurationDto> GetLocalizationConfigAsync() { Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); var localizationConfig = new ApplicationLocalizationConfigurationDto(); localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync()); foreach (var resource in _localizationOptions.Resources.Values) { var dictionary = new Dictionary <string, string>(); var localizer = _serviceProvider.GetRequiredService( typeof(IStringLocalizer <>).MakeGenericType(resource.ResourceType) ) as IStringLocalizer; foreach (var localizedString in localizer.GetAllStrings()) { dictionary[localizedString.Name] = localizedString.Value; } localizationConfig.Values[resource.ResourceName] = dictionary; } localizationConfig.CurrentCulture = GetCurrentCultureInfo(); Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetLocalizationConfigAsync()"); return(localizationConfig); }
public async Task <IViewComponentResult> InvokeAsync() { var languages = await _languageProvider.GetLanguagesAsync(); List <LanguageInfo> list = new List <LanguageInfo>(); foreach (var entity in languages) { entity.FlagIcon = GetFlagIcon(entity.CultureName); if (!string.IsNullOrEmpty(entity.FlagIcon)) { list.Add(entity); } } var currentLanguage = languages.FindByCulture( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name ); currentLanguage.FlagIcon = GetFlagIcon(currentLanguage.CultureName); var model = new LanguageSwitchViewComponentModel { CurrentLanguage = currentLanguage, OtherLanguages = list.Where(l => l != currentLanguage).ToList() }; return(View("~/Themes/AdminLTE/Components/Toolbar/LanguageSwitch/LoginDefault.cshtml", model)); }
public void Test() { foreach (var languageInfo in _languageProvider.GetLanguagesAsync().Result) { CultureHelper.Use(languageInfo.CultureName); Console.WriteLine($"当前语言:{languageInfo.DisplayName}[{languageInfo.CultureName}]"); Console.WriteLine(_localizer["HelloMessage", "张三"]); Console.WriteLine(); } }
public async Task <IViewComponentResult> InvokeAsync() { var languages = await _languageProvider.GetLanguagesAsync(); var currentLanguage = languages.FindByCulture( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name ); var model = new LanguageSwitchViewComponentModel { CurrentLanguage = currentLanguage, OtherLanguages = languages.Where(l => l != currentLanguage).ToList() }; return(View("~/Themes/Basic/Components/Toolbar/LanguageSwitch/Default.cshtml", model)); }
/// <summary> /// 创建报警级别 /// </summary> /// <param name="input"></param> /// <returns></returns> /// <remarks>Create by 2</remarks> //[Authorize(TestServicePermissions.FaultGrade.Create)] public virtual async Task <FaultGradeDto> CreateAsync(CreateFaultGradeInput input) { var ccc = _currentUser.Name; var languages = await _languageProvider.GetLanguagesAsync(); var currentLanguage = languages.FindByCulture( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name ); var json = JsonConvert.SerializeObject(input); var obj = JsonConvert.DeserializeObject(json); _logger.LogInformation(currentLanguage.CultureName); //var ddd =await _identityUserLookupAppService.FindByIdAsync(new Guid("B3A4DE5A-0338-F82F-C71F-39FC33D8558A")); var existFaultGrade = await _faultGradeRepository.FirstOrDefaultAsync(p => p.FaultGradeNo == input.FaultGradeNo); if (existFaultGrade != null) { var aaa = _localizer["HelloWorld"]; var bbb = _localizer["FaultNoAlreadyExistsException", input.FaultGradeNo]; //throw new BusinessException("P000001", _localizer["FaultNoAlreadyExistsException", input.FaultGradeNo]); //throw new BusinessException("P00001", $"报警级别编号【{input.FaultGradeNo}】已存在"); throw new UserFriendlyException(_localizer["FaultNoAlreadyExistsException", input.FaultGradeNo]); } //var faultGrade = new FaultGrade( // input.FaultGradeNo, // input.FaultGradeName, // input.FaultGradeColor); //var result = await _faultGradeRepository.InsertAsync(faultGrade); //return ObjectMapper.Map<FaultGrade, FaultGradeDto>(result); var entity = ObjectMapper.Map <CreateFaultGradeInput, FaultGrade>(input); var result = await _faultGradeRepository.InsertAsync(entity); return(ObjectMapper.Map <FaultGrade, FaultGradeDto>(result)); }
public async Task <IViewComponentResult> InvokeAsync() { var languages = await _languageProvider.GetLanguagesAsync(); var currentLanguage = languages.FindByCulture( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name ); var model = new LanguageSelectionViewModel { CurrentLanguage = currentLanguage, Languages = languages.Where(l => l != currentLanguage).ToList() .ToList(), CurrentUrl = Request.Path }; return(View("~/Themes/AdminLTE/Components/AccountLanguages/Default.cshtml", model));; }
public async Task <IViewComponentResult> InvokeAsync() { var languages = await _languageProvider.GetLanguagesAsync(); var currentLanguage = languages.FindByCulture( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name ); if (currentLanguage == null) { var abpRequestLocalizationOptionsProvider = HttpContext.RequestServices.GetRequiredService <IAbpRequestLocalizationOptionsProvider>(); var localizationOptions = await abpRequestLocalizationOptionsProvider.GetLocalizationOptionsAsync(); if (localizationOptions.DefaultRequestCulture != null) { currentLanguage = new LanguageInfo( localizationOptions.DefaultRequestCulture.Culture.Name, localizationOptions.DefaultRequestCulture.UICulture.Name, localizationOptions.DefaultRequestCulture.UICulture.DisplayName); } else { currentLanguage = new LanguageInfo( CultureInfo.CurrentCulture.Name, CultureInfo.CurrentUICulture.Name, CultureInfo.CurrentUICulture.DisplayName); } } var model = new LanguageSwitchViewComponentModel { CurrentLanguage = currentLanguage, OtherLanguages = languages.Where(l => l != currentLanguage).ToList() }; return(View("LanguageSwitch/Default.cshtml", model)); }
protected virtual async Task <ApplicationLocalizationConfigurationDto> GetLocalizationConfigAsync() { var localizationConfig = new ApplicationLocalizationConfigurationDto(); localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync()); foreach (var resource in _localizationOptions.Resources.Values) { var dictionary = new Dictionary <string, string>(); var localizer = _serviceProvider.GetRequiredService( typeof(IStringLocalizer <>).MakeGenericType(resource.ResourceType) ) as IStringLocalizer; foreach (var localizedString in localizer.GetAllStrings()) { dictionary[localizedString.Name] = localizedString.Value; } localizationConfig.Values[resource.ResourceName] = dictionary; } localizationConfig.CurrentCulture = GetCurrentCultureInfo(); if (_localizationOptions.DefaultResourceType != null) { localizationConfig.DefaultResourceName = LocalizationResourceNameAttribute.GetName( _localizationOptions.DefaultResourceType ); } localizationConfig.LanguagesMap = _localizationOptions.LanguagesMap; localizationConfig.LanguageFilesMap = _localizationOptions.LanguageFilesMap; return(localizationConfig); }
public static IReadOnlyList <LanguageInfo> GetLanguages(this ILanguageProvider languageProvider) { return(AsyncHelper.RunSync(() => languageProvider.GetLanguagesAsync())); }