예제 #1
0
        /// <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);
        }
예제 #3
0
        public static bool IsValidCultureCode(string cultureCode)
        {
            if (cultureCode.IsNullOrWhiteSpace())
            {
                return(false);
            }

            try
            {
                CultureInfoHelper.Get(cultureCode);
                return(true);
            }
            catch (CultureNotFoundException)
            {
                return(false);
            }
        }
예제 #4
0
        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);
        }