Exemplo n.º 1
0
        private NameValueCollection GetResources()
        {
            string currentCulture = ResourceManager.CurrentCultureName;
            string defaultCulture = LocalizationConfiguration.GetConfig().DefaultCultureName;
            string userInterface  = HttpContext.Current.Request.ServerVariables["URL"];

            bool languagePreviewMode = false;

            if (HttpContext.Current.Request.Cookies["LanguagePreviewMode"] != null)
            {
                languagePreviewMode = (HttpContext.Current.Request.Cookies["LanguagePreviewMode"].Value.ToString() == "1");
            }

            string cacheKey = string.Empty;
            NameValueCollection resources = new NameValueCollection();

            string sqlSelect = @"SELECT LangInterfaceName from tblLangInterface 
									WHERE LangInterfaceName = @LangInterfaceName OR LangInterfaceName LIKE 'GLOBAL.%'
								"                                ;

            SqlParameter[] sqlParams = { new SqlParameter("@LangInterfaceName", userInterface) };

            DataTable dtInterface = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelect, sqlParams).Tables[0];

            foreach (DataRow drInterface in dtInterface.Rows)
            {
                string interfaceToLoad = drInterface["LangInterfaceName"].ToString();
                cacheKey = "SQLLocalization:" + defaultCulture + ':' + currentCulture + ':' + interfaceToLoad + ":" + languagePreviewMode.ToString();
                NameValueCollection currentResource = (NameValueCollection)HttpRuntime.Cache[cacheKey];
                if (currentResource == null)
                {
                    currentResource = LoadResources(defaultCulture, currentCulture, interfaceToLoad, languagePreviewMode);
                    //-- Both committed and uncommited are cached here
                    HttpRuntime.Cache.Insert(cacheKey, resources, null, DateTime.Now.AddMinutes(cacheDuration), Cache.NoSlidingExpiration);
                }

                foreach (string name in currentResource.AllKeys)
                {
                    //-- Because we may have uncommitted values, the sql is sorted to load those up first, if a committed version comes along, to not load it.
                    if (resources[name] == null)
                    {
                        resources.Add(name, currentResource[name].ToString());
                    }
                }
            }
            return(resources);
        }
Exemplo n.º 2
0
        protected override void Render(HtmlTextWriter writer)
        {
            LocalizedImageData data = ResourceManager.GetImage(key);

            if (data != null)
            {
                base.Src    = string.Format(imageUrlFormat, LocalizationConfiguration.GetConfig().ImagePath, ResourceManager.CurrentCultureName, base.Src);
                base.Width  = data.Width;
                base.Height = data.Height;
                base.Alt    = data.Alt;
            }
            if (colon)
            {
                base.Alt += ResourceManager.Colon;
            }
            base.Render(writer);
        }
Exemplo n.º 3
0
        private NameValueCollection GetResources()
        {
            string currentCulture = ResourceManager.CurrentCultureName;
            string defaultCulture = LocalizationConfiguration.GetConfig().DefaultCultureName;
            string cacheKey       = "Localization:" + defaultCulture + ':' + currentCulture;

            if (HttpRuntime.Cache[cacheKey] == null)
            {
                NameValueCollection resource = new NameValueCollection();
                LoadResources(resource, defaultCulture, cacheKey);
                if (defaultCulture != currentCulture)
                {
                    try
                    {
                        LoadResources(resource, currentCulture, cacheKey);
                    }
                    catch (FileNotFoundException)
                    {}
                }
            }
            return((NameValueCollection)HttpRuntime.Cache[cacheKey]);
        }
Exemplo n.º 4
0
        private Hashtable GetImages()
        {
            string currentCulture = ResourceManager.CurrentCultureName;
            string defaultCulture = LocalizationConfiguration.GetConfig().DefaultCultureName;
            string cacheKey       = "LocalizationImage:" + defaultCulture + ':' + currentCulture;

            if (HttpRuntime.Cache[cacheKey] == null)
            {
                Hashtable resource = new Hashtable();
                LoadImage(resource, defaultCulture, cacheKey);
                if (defaultCulture != currentCulture)
                {
                    try
                    {
                        LoadImage(resource, currentCulture, cacheKey);
                    }
                    catch (FileNotFoundException)
                    {}
                }
            }
            return((Hashtable)HttpRuntime.Cache[cacheKey]);
        }
Exemplo n.º 5
0
        private void LoadCulture(ref string path)
        {
            string[] pathParts      = path.Trim('/').Split('/');
            string   defaultCulture = LocalizationConfiguration.GetConfig().DefaultCultureName;

            if (pathParts.Length > 0 && pathParts[0].Length > 0)
            {
                try {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(pathParts[0]);
                    path = path.Remove(0, pathParts[0].Length + 1);
                }catch (Exception ex) {
                    if (!(ex is ArgumentNullException) && !(ex is ArgumentException))
                    {
                        throw;
                    }
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(defaultCulture);
                }
            }
            else
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(defaultCulture);
            }
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
        }