public static string LocalizeEnum <T>(T value)
            where T : struct
        {
            string enumName = typeof(T).Name;
            string fullKey  = string.Format("E_{0}_{1}", enumName, value.ToString());

            return(StringLocalizer.Localize(fullKey));
        }
        public static string LocalizeController <T>(string key)
            where T : ControllerBase
        {
            string controllerName = typeof(T).Name;

            controllerName = controllerName.Remove(controllerName.Length - 10);
            string fullKey = string.Format("C_{0}_{1}", controllerName, key);

            return(StringLocalizer.Localize(fullKey));
        }
        public static string LocalizeModel <T>(string key)
            where T : class
        {
            string modelName = typeof(T).Name;

            modelName = modelName.Remove(modelName.Length - 9);
            string fullKey = string.Format("M_{0}_{1}", modelName, key);

            return(StringLocalizer.Localize(fullKey));
        }
        public static string LocalizeView(string key, object languageId, string defaultValue)
        {
            string fullKey = string.Format("V_{0}", key);

            return(StringLocalizer.Localize(fullKey, languageId, defaultValue));
        }
        public static string LocalizeView(string key)
        {
            string fullKey = string.Format("V_{0}", key);

            return(StringLocalizer.Localize(fullKey));
        }
        public static string LocalizeBusiness(string key)
        {
            string fullKey = string.Format("B_{0}", key);

            return(StringLocalizer.Localize(fullKey));
        }
Пример #7
0
        private async Task <InstalledPackage> ConvertFrom(Package item, CancellationToken cancellationToken, IProgress <ProgressData> progress = default)
        {
            Logger.Debug("Getting details about package {0}...", item.Id.Name);
            string   installLocation;
            DateTime installDate;

            try
            {
                installLocation = item.InstalledLocation?.Path;
            }
            catch (Exception e)
            {
                Logger.Warn(e, "Installed location for package {0} is invalid. This may be expected for some installed packages.", item.Id.Name);
                installLocation = null;
            }

            if (installLocation != null)
            {
                try
                {
                    installDate = item.InstalledDate.LocalDateTime;
                }
                catch (Exception e)
                {
                    Logger.Warn(e, "Installed date for package {0} is invalid. This may be expected for some installed packages.", item.Id.Name);
                    installDate = DateTime.MinValue;
                }
            }
            else
            {
                installDate = DateTime.MinValue;
            }

            MsixPackageVisuals details;
            RegistryMountState hasRegistry;

            if (installLocation == null)
            {
                hasRegistry = RegistryMountState.NotApplicable;
                details     = new MsixPackageVisuals(item.Id.Name, item.Id.Publisher, null, null, "#000000", 0);
            }
            else
            {
                details = await GetVisualsFromManifest(installLocation, cancellationToken).ConfigureAwait(false);

                hasRegistry = await registryManager.GetRegistryMountState(installLocation, item.Id.Name, cancellationToken, progress).ConfigureAwait(false);
            }

            var pkg = new InstalledPackage
            {
                DisplayName          = details.DisplayName,
                Name                 = item.Id.Name,
                Image                = details.Logo,
                PackageId            = item.Id.FullName,
                InstallLocation      = installLocation,
                PackageFamilyName    = item.Id.FamilyName,
                Description          = details.Description,
                DisplayPublisherName = details.DisplayPublisherName,
                Publisher            = item.Id.Publisher,
                Architecture         = item.Id.Architecture.ToString(),
                IsFramework          = item.IsFramework,
                IsOptional           = item.IsOptional,
                TileColor            = details.Color,
                PackageType          = details.PackageType,
                Version              = new Version(item.Id.Version.Major, item.Id.Version.Minor, item.Id.Version.Build, item.Id.Version.Revision),
                SignatureKind        = Convert(item.SignatureKind),
                HasRegistry          = hasRegistry,
                InstallDate          = installDate,
                AppInstallerUri      = item.GetAppInstallerInfo()?.Uri
            };

            if (pkg.Architecture[0] == 'X')
            {
                pkg.Architecture = "x" + pkg.Architecture.Substring(1);
            }

            if (installLocation != null && (pkg.DisplayName?.StartsWith("ms-resource:", StringComparison.Ordinal) ??
                                            pkg.DisplayPublisherName?.StartsWith("ms-resource:", StringComparison.Ordinal) ??
                                            pkg.Description?.StartsWith("ms-resource:", StringComparison.Ordinal) == true))
            {
                var priFile = Path.Combine(installLocation, "resources.pri");

                pkg.DisplayName          = StringLocalizer.Localize(priFile, pkg.Name, pkg.PackageId, pkg.DisplayName);
                pkg.DisplayPublisherName = StringLocalizer.Localize(priFile, pkg.Name, pkg.PackageId, pkg.DisplayPublisherName);
                pkg.Description          = StringLocalizer.Localize(priFile, pkg.Name, pkg.PackageId, pkg.Description);

                if (string.IsNullOrEmpty(pkg.DisplayName))
                {
                    pkg.DisplayName = pkg.Name;
                }

                if (string.IsNullOrEmpty(pkg.DisplayPublisherName))
                {
                    pkg.DisplayPublisherName = pkg.Publisher;
                }
            }

            return(pkg);
        }
Пример #8
0
 protected string Localize(string key, string defaultValue)
 {
     return(StringLocalizer.Localize(key, CurrentUserContext.CurrentLanguage.Id, defaultValue));
 }