Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C#

Unleash PropertyGrid with Dynamic Properties and Globalization

Rate me:
Please Sign up or sign in to vote.
4.97/5 (24 votes)
29 Jan 2004CPOL9 min read 126.5K   4.8K   88  
The article presents a way to enhance the use of the PropertyGid control with dynamic properties and globalization
using System;
using System.Resources;
using System.Globalization;
using System.Collections;

namespace CustomControls.Globalization
{
	public class Dictionary
	{
		
		private static ResXResourceReader _Resx=null;
		private static string path="Dictionary.resx";
		private static Hashtable _HT=null;


		private static ResXResourceReader Resx
		{
			get
			{
				if(System.IO.File.Exists(path))
				{
					if(_Resx==null)
					{
						_Resx= new ResXResourceReader(path);
					}
				}
				return _Resx;
			}
		}

		private static Hashtable HT
		{
			get
			{
				if(_HT==null && Resx!=null)
				{
					_HT= new Hashtable();
					foreach(DictionaryEntry de in Resx )
					{
						_HT.Add(de.Key, de.Value);
					}
					_Resx.Close();
					_Resx=null;
				}
				return _HT;
			}
		}


		

	
		public Dictionary()
		{
		
		}

	
		public static string Translate(string Text,CultureInfo ci)
		{
			if(HT!=null)
			{
				string langText=ci.TwoLetterISOLanguageName.ToUpper()+ "_" + Text;
				object sText= HT[langText].ToString();
				if(sText!=null){return sText.ToString();}
				else{return null;}
			}
			return Text;
		}

		public static string Translate(string Text)
		{
			if(HT!=null)
			{
				CultureInfo ci=System.Globalization.CultureInfo.CurrentCulture;
				object sText=HT[ci.TwoLetterISOLanguageName.ToUpper()+ "_" + Text];
				if(sText!=null){return sText.ToString();}
				else{return null;}
			}
			return null;
		}


	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions