Data Access Approach to Implement Multilingual ASP.NET Application
The following class will help implement multilinguality in ASP.NET application storing strings and other multilingual paramaters in the database. This Data Access class fetches data and stores it into the class instance. (This class was written in 2002, so some code/design conventions used here are out of date...)
/// /// class Config /// for multiLanguage environments /// public class Config { private string _ENCODING = String.Empty; private Hashtable _STRINGS = new Hashtable(); public string Encoding { get { return _ENCODING; } set { _ENCODING = value; } } public Hashtable Strings { get { return _STRINGS; } set { _STRINGS = value; } } /// /// Config /// constructor /// public Config(int iPageId, int iLang) { SqlDataReader dataReader = null; /// make database call DataLayer dLayer = new DataLayer(); SqlParameter[] prams = { dLayer.MakeInParam("@p_page_id", SqlDbType.Int, 4, iPageId), dLayer.MakeInParam("@p_lang_id", SqlDbType.Int, 4, iLang), dLayer.MakeOutParam("@p_encoding", SqlDbType.NVarChar, 15) }; dLayer.RunProc("P_GET_STRINGS", prams, out dataReader); /// put values into HashTable while(dataReader.Read()) { this.Strings[dataReader[0].ToString()] = dataReader[1].ToString(); } dLayer.Close(); /// set encoding this.Encoding = prams[2].Value.ToString(); } /// /// LoadString /// this method is responsible /// to get string value by id /// public string LoadString(string id) { return this.Strings[id].ToString(); } /// /// Dispose() /// release resources /// public void Dispose() { if (_STRINGS != null) { _STRINGS = null; } } }
Sunday, November 30, 2003 1:26 AM