Esempio n. 1
0
        public ILocalizableString CreateModuleLocalizableString(TypeInfo type, string text, params object[] args)
        {
            if (TypeHelper.GetActualType(type, out var instanceType))
            {
                throw new LocalizationException(StringLocal.Format($"type {type} not found ActualType"));
            }
            var moduleId            = type.Assembly.GetName().Name;
            var AvailableExtensions = _ioc.Resolve <IExtensionManager>().AvailableFeatures();
            var ModuleName          = AvailableExtensions.FirstOrDefault(f => f.Id == moduleId)?.Name;

            if (string.IsNullOrEmpty(ModuleName))
            {
                ModuleName = AvailableExtensions.FirstOrDefault(t => t.SubAssembly.Contains(moduleId))?.Name;
            }

            Check.NotNull(ModuleName, $"Can't find [{moduleId}] in AvailableFeatures");
            return(new LocalizableString(ModuleName, text, args));
        }
Esempio n. 2
0
        private LanguageInfo GetCurrentLanguage()
        {
            var languages = _languageProvider.GetLanguages();

            if (languages.Count <= 0)
            {
                throw new LocalizationException(StringLocal.Format("No language defined in this application."));
            }

            var currentCultureName = CultureInfo.CurrentUICulture.Name;

            //Try to find exact match
            var currentLanguage = languages.FirstOrDefault(l => l.Name == currentCultureName);

            if (currentLanguage != null)
            {
                return(currentLanguage.AutoMapTo <LanguageInfo>());
            }

            //Try to find best match
            currentLanguage = languages.FirstOrDefault(l => currentCultureName.StartsWith(l.Name));
            if (currentLanguage != null)
            {
                return(currentLanguage.AutoMapTo <LanguageInfo>());
            }

            //Try to find default language
            currentLanguage = languages.FirstOrDefault(l => l.IsDefault);
            if (currentLanguage != null)
            {
                return(currentLanguage.AutoMapTo <LanguageInfo>());
            }

            //Get first one
            return(languages[0].AutoMapTo <LanguageInfo>());
        }