/// <summary> /// Sets the default language for a tenant or the host. /// </summary> /// <param name="tenantId">Tenant Id of null for host</param> /// <param name="languageName">Name of the language.</param> public virtual async Task SetDefaultLanguageAsync(int?tenantId, string languageName) { var cultureInfo = CultureInfoHelper.Get(languageName); if (tenantId.HasValue) { await settingManager.ChangeSettingForTenantAsync(tenantId.Value, LocalizationSettingNames.DefaultLanguage, cultureInfo.Name); } else { await settingManager.ChangeSettingForApplicationAsync(LocalizationSettingNames.DefaultLanguage, cultureInfo.Name); } }
protected virtual IMultiTenantLocalizationDictionary CreateLocalizationDictionary(LanguageInfo language) { var internalDictionary = internalProvider.Dictionaries.GetOrDefault(language.Name) ?? new EmptyDictionary(CultureInfoHelper.Get(language.Name)); var dictionary = iocManager.Resolve <IMultiTenantLocalizationDictionary>(new { sourceName = sourceName, internalDictionary = internalDictionary }); return(dictionary); }
public static bool IsValidCultureCode(string cultureCode) { if (cultureCode.IsNullOrWhiteSpace()) { return(false); } try { CultureInfoHelper.Get(cultureCode); return(true); } catch (CultureNotFoundException) { return(false); } }
public static string ReturnGivenNameOrThrowException( ILocalizationConfiguration configuration, string sourceName, string name, CultureInfo culture, ILogger logger = null) { var exceptionMessage = $"Can not find '{name}' in localization source '{sourceName}'!"; if (!configuration.ReturnGivenTextIfNotFound) { throw new StudioXException(exceptionMessage); } if (configuration.LogWarnMessageIfNotFound) { (logger ?? LogHelper.Logger).Warn(exceptionMessage); } string notFoundText; #if NET46 notFoundText = configuration.HumanizeTextIfNotFound ? name.ToSentenceCase(culture) : name; #else using (CultureInfoHelper.Use(culture)) { notFoundText = configuration.HumanizeTextIfNotFound ? name.ToSentenceCase() : name; } #endif return(configuration.WrapGivenTextIfNotFound ? $"[{notFoundText}]" : notFoundText); }