/// <summary> /// Loads the provider. /// </summary> /// <returns> /// [true] if the provider has been loaded. /// </returns> private bool LoadProvider() { if (this.LocalizationService == null) { return(false); } // This config value could tell the provider where to find the translations, // set to 0 though, will be looked up after initialization in the provider itself. NameValueCollection configValues = new NameValueCollection { { "containerid", "0" } }; TranslationProvider translationProviderProvider = new TranslationProvider(); // Instantiate the provider translationProviderProvider.Initialize(ProviderName, configValues); // Add it at the end of the list of providers. try { this.LocalizationService.Providers.Add(translationProviderProvider); } catch (NotSupportedException notSupportedException) { Log.Error("[Localization] Error add provider to the Localization Service.", notSupportedException); return(false); } LoadTranslations(translationProviderProvider); return(true); }
/// <summary> /// Load the translations. /// </summary> /// <param name="localizationProvider"> /// The localization Provider. /// </param> private static void LoadTranslations(TranslationProvider localizationProvider) { if (localizationProvider != null) { localizationProvider.LoadTranslations(); return; } Log.Info("[Localization] Translation provider not found, no translations loaded."); }
/// <summary> /// Reloads the provider. /// </summary> private void ReloadProvider() { lock (SyncLock) { TranslationProvider translationProvider = this.GetTranslationProvider(); initialized = this.UnLoadProvider(translationProvider); if (initialized) { return; } initialized = this.LoadProvider(); } }
/// <summary> /// Resets the module into an uninitialized state. /// </summary> /// <param name="context"> /// The context. /// </param> /// <remarks> /// <para> /// This method is usually not called when running under a web application since the web app may be shut down very /// abruptly, but your module should still implement it properly since it will make integration and unit testing /// much simpler. /// </para> /// <para> /// Any work done by /// <see /// cref="M:EPiServer.Framework.IInitializableModule.Initialize(EPiServer.Framework.Initialization.InitializationEngine)" /> /// as well as any code executing on /// <see cref="E:EPiServer.Framework.Initialization.InitializationEngine.InitComplete" /> /// should be reversed. /// </para> /// </remarks> public void Uninitialize(InitializationEngine context) { // If there is no context, we can't do anything. if (context == null) { return; } // If already uninitialized, no need to do it again. if (!initialized) { return; } Log.Info("[Localization] Uninitializing translation provider."); TranslationProvider translationProvider = this.GetTranslationProvider(); initialized = this.UnLoadProvider(translationProvider); Log.Info("[Localization] Translation provider uninitialized."); }
/// <summary> /// Loads the provider. /// </summary> /// <returns> /// [true] if the provider has been loaded. /// </returns> private bool LoadProvider() { if (this.LocalizationService == null) { return false; } // This config value could tell the provider where to find the translations, // set to 0 though, will be looked up after initialization in the provider itself. NameValueCollection configValues = new NameValueCollection { { "containerid", "0" } }; TranslationProvider translationProviderProvider = new TranslationProvider(); // Instantiate the provider translationProviderProvider.Initialize(ProviderName, configValues); // Add it at the end of the list of providers. try { this.LocalizationService.Providers.Add(translationProviderProvider); } catch (NotSupportedException notSupportedException) { Log.Error("[Localization] Error add provider to the Localization Service.", notSupportedException); return false; } LoadTranslations(translationProviderProvider); return true; }