Пример #1
0
        private static void AddProvider(ProviderBasedLocalizationService service)
        {
            try
            {
                var langFolderVirtualPath = Settings.AutoPopulated.LangFolderVirtualPath;
                if (string.IsNullOrEmpty(langFolderVirtualPath))
                {
                    Log.Error("LangFolderVirtualPath undefined.");
                    return;
                }

                // Due to what is likely bug in Episerver, there needs to be a physical path with the same
                // name as the virtual path, or else GetInitializedProvider fails since it can't listen to changes in a network folder.
                var physicalDirectory = HostingEnvironment.MapPath(langFolderVirtualPath);
                if (!Directory.Exists(physicalDirectory))
                {
                    Directory.CreateDirectory(physicalDirectory);
                }

                //a VPP with the path below must be registered in the sites configuration.
                var localizationProviderInitializer = new VirtualPathXmlLocalizationProviderInitializer(GenericHostingEnvironment.VirtualPathProvider);
                var localizationProvider            = localizationProviderInitializer.GetInitializedProvider(langFolderVirtualPath, ProviderName);

                //Inserts the provider first in the provider list so that it is prioritized over default providers.
                service.Providers.Insert(0, localizationProvider);

                Log.Debug("LocalizationProvider added");
            }
            catch (Exception e)
            {
                Log.Error("Failed to add custom localization provider.", e);
            }
        }
        private static void AddProvider(ProviderBasedLocalizationService service)
        {
            try
            {
                var langFolderVirtualPath = Settings.AutoPopulated.LangFolderVirtualPath;
                if (string.IsNullOrEmpty(langFolderVirtualPath))
                {
                    Log.Error("LangFolderVirtualPath undefined.");
                    return;
                }

                // Due to what is likely bug in Episerver, there needs to be a physical path with the same
                // name as the virtual path, or else GetInitializedProvider fails since it can't listen to changes in a network folder.
                var physicalDirectory = HostingEnvironment.MapPath(langFolderVirtualPath);
                if (!Directory.Exists(physicalDirectory))
                {
                    Directory.CreateDirectory(physicalDirectory);
                }

                //a VPP with the path below must be registered in the sites configuration.
                var localizationProviderInitializer = new VirtualPathXmlLocalizationProviderInitializer(GenericHostingEnvironment.VirtualPathProvider);
                var localizationProvider = localizationProviderInitializer.GetInitializedProvider(langFolderVirtualPath, ProviderName);

                //Inserts the provider first in the provider list so that it is prioritized over default providers.
                service.Providers.Insert(0, localizationProvider);

                Log.Debug("LocalizationProvider added");
            }
            catch(Exception e)
            {
                Log.Error("Failed to add custom localization provider." , e);
            }
        }