public static LocaleCollection GetSupportedLocales()
 {
     var supportedLocales = new LocaleCollection();
     foreach (KeyValuePair<string, Locale> kvp in LocaleController.Instance.GetLocales(Null.NullInteger))
     {
         supportedLocales.Add(kvp.Key, kvp.Value);
     }
     return supportedLocales;
 }
 public static LocaleCollection GetEnabledLocales()
 {
     PortalSettings objPortalSettings = PortalController.Instance.GetCurrentPortalSettings();
     var enabledLocales = new LocaleCollection();
     foreach (KeyValuePair<string, Locale> kvp in LocaleController.Instance.GetLocales(objPortalSettings.PortalId))
     {
         enabledLocales.Add(kvp.Key, kvp.Value);
     }
     return enabledLocales;
 }
        /// <Summary>
        /// GetSupportedLocales returns the list of locales from the locales.xml file.
        /// </Summary>
        public static LocaleCollection GetSupportedLocales()
        {
            string cacheKey = "dotnetnuke-supportedlocales";
            LocaleCollection supportedLocales = (LocaleCollection)DataCache.GetCache(cacheKey);

            if (supportedLocales == null)
            {
                supportedLocales = new LocaleCollection();
                string filePath = Globals.ApplicationMapPath + SupportedLocalesFile.Substring(1).Replace("/", "\\");

                if (!File.Exists(filePath))
                {
                    try
                    {
                        // First access to locales.xml, create using template
                        File.Copy(Globals.ApplicationMapPath + ApplicationConfigDirectory.Substring(1).Replace("/", "\\") + "\\Locales.xml.config", Globals.ApplicationMapPath + SupportedLocalesFile.Substring(1).Replace("/", "\\"));
                    }
                    catch
                    {
                        Locale objLocale = new Locale();
                        objLocale.Text = "English";
                        objLocale.Code = "en-US";
                        objLocale.Fallback = "";
                        supportedLocales.Add("en-US", objLocale);
                        return supportedLocales; //Will be Empty and not cached
                    }
                }

                CacheDependency dp = new CacheDependency(filePath);

                XPathDocument doc = new XPathDocument(filePath);
                foreach (XPathNavigator nav in doc.CreateNavigator().Select("root/language"))
                {
                    if (nav.NodeType != XPathNodeType.Comment)
                    {
                        Locale objLocale = new Locale();
                        objLocale.Text = nav.GetAttribute("name", "");
                        objLocale.Code = nav.GetAttribute("key", "");
                        objLocale.Fallback = nav.GetAttribute("fallback", "");

                        supportedLocales.Add(nav.GetAttribute("key", ""), objLocale);
                    }
                }
                if (Globals.PerformanceSetting != Globals.PerformanceSettings.NoCaching)
                {
                    DataCache.SetCache(cacheKey, supportedLocales, dp);
                }
            }

            return supportedLocales;
        }
Beispiel #4
0
        private static LocaleCollection ParseEnabledLocales(XmlNode nodeEnabledLocales, int PortalId)
        {
            var defaultLocale = LocaleController.Instance.GetDefaultLocale(PortalId);
            var returnCollection = new LocaleCollection { { defaultLocale.Code, defaultLocale } };
            var clearCache = false;
            foreach (XmlNode node in nodeEnabledLocales.SelectNodes("//locale"))
            {
                var cultureCode = node.InnerText;
                var locale = LocaleController.Instance.GetLocale(cultureCode);
                if (locale == null)
                {
                    // if language does not exist in the installation, create it
                    locale = new Locale {Code = cultureCode, Fallback = Localization.SystemLocale, Text = CultureInfo.CreateSpecificCulture(cultureCode).NativeName};
                    Localization.SaveLanguage(locale,false);
                    clearCache = true;
                }

                if (locale.Code != defaultLocale.Code)
                {
                    returnCollection.Add(locale.Code, locale);
                }
            }
            if (clearCache)
            {
                DataCache.ClearHostCache(true);
            }
            return returnCollection;
        }
        public static LocaleCollection GetEnabledLocales()
        {
            PortalSettings objPortalSettings = PortalController.GetCurrentPortalSettings();
            string FilePath = HttpContext.Current.Server.MapPath(ApplicationConfigDirectory + "/Locales.Portal-" + objPortalSettings.PortalId + ".xml");

            if (File.Exists(FilePath))
            {
                //locales have been previously disabled
                string cacheKey = "dotnetnuke-enabledlocales" + objPortalSettings.PortalId;
                LocaleCollection enabledLocales = (LocaleCollection)DataCache.GetCache(cacheKey);

                if (enabledLocales == null)
                {
                    enabledLocales = new LocaleCollection();
                    XmlDocument xmlInactiveLocales = new XmlDocument();
                    bool bXmlLoaded = false;

                    //load inactive locales xml file
                    try
                    {
                        xmlInactiveLocales.Load(FilePath);
                        bXmlLoaded = true;
                    }
                    catch
                    {
                    }

                    CacheDependency dp = new CacheDependency(FilePath);
                    XmlDocument d = new XmlDocument();
                    d.Load(FilePath);

                    LocaleCollection supportedLocales = GetSupportedLocales();
                    foreach (string localeCode in supportedLocales.AllKeys)
                    {
                        if (!bXmlLoaded || xmlInactiveLocales.SelectSingleNode("//locales/inactive/locale[.='" + localeCode + "']") == null)
                        {
                            Locale objLocale = new Locale();
                            objLocale.Text = supportedLocales[localeCode].Text;
                            objLocale.Code = localeCode;
                            objLocale.Fallback = supportedLocales[localeCode].Fallback;

                            enabledLocales.Add(localeCode, objLocale);
                        }
                    }
                    if (Globals.PerformanceSetting != Globals.PerformanceSettings.NoCaching)
                    {
                        DataCache.SetCache(cacheKey, enabledLocales, dp);
                    }
                }

                return enabledLocales;
            }
            else
            {
                // if portal specific xml file does not exist, all locales have been enabled, so just return supportedlocales
                return GetSupportedLocales();
            }
        }