|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
dynamic variable namingI am building a multilanguage asp .net application using masterpages. All the pages are derived from one class and the class has a function which finds a specific label on the masterpage and prints the output messages there. public void ShowMessage(string outputMessage) { Label lblOutput = (Label)Master.FindControl("lblMessage"); lblOutput.Text = outputMessage; } i have a string constants class and the strings with two languages are definded there like this public struct InHouseMessages { public const string OPERATION_SUCCESS = "yehu"; public const string OPERATION_SUCCESS_ENG = "yeah"; public const string OPERATION_FAILURE = "nayir"; public const string OPERATION_FAILURE_ENG = "damn"; public const string OPERATION_STUCK = "hayiiiiiiirrr"; public const string OPERATION_STUCK_ENG = "noooooooo"; } What i want to do is make the ShowMessage function language aware like this public void ShowMessage(string outputMessage, bool isENG) { if(isENG) lblMessage.text = outputMessage+_ENG; else lblMessage.text = outputMessage; } i mean i want to programmatically change the variable name befoure the variable gets its string value. Hi. Simply use a List<string> (.Net 2.0) or a StringCollection to store your
messages instead of the ugly hardcoded consts. Then you can get your string using MyStringCollection[OutputMessage + '_Eng'] for example. 'Hans Olav. <kaanen***@gmail.com> wrote in message Show quote news:1148890764.007729.268010@y43g2000cwc.googlegroups.com... > Hi, > > I am building a multilanguage asp .net application using masterpages. > All the pages are derived from one class and the class has a function > which finds a specific label on the masterpage and prints the output > messages there. > > public void ShowMessage(string outputMessage) > { > Label lblOutput = (Label)Master.FindControl("lblMessage"); > lblOutput.Text = outputMessage; > } > > i have a string constants class and the strings with two languages are > definded there like this > > public struct InHouseMessages > { > public const string OPERATION_SUCCESS = "yehu"; > public const string OPERATION_SUCCESS_ENG = "yeah"; > public const string OPERATION_FAILURE = "nayir"; > public const string OPERATION_FAILURE_ENG = "damn"; > public const string OPERATION_STUCK = "hayiiiiiiirrr"; > public const string OPERATION_STUCK_ENG = "noooooooo"; > } > > What i want to do is make the ShowMessage function language aware like > this > > public void ShowMessage(string outputMessage, bool isENG) > { > if(isENG) > lblMessage.text = outputMessage+_ENG; > else > lblMessage.text = outputMessage; > } > > i mean i want to programmatically change the variable name befoure the > variable gets its string value. > Have you considerred storing these items as resources where they could be
easily localized (as opposed to trying to handle the localization on your own)? http://www.codeproject.com/dotnet/Localization.asp is a quick example but if you google on C# Resource Localiztion it should bring up a bunch of articles for you. Cheers, Greg Young <kaanen***@gmail.com> wrote in message Show quote news:1148890764.007729.268010@y43g2000cwc.googlegroups.com... > Hi, > > I am building a multilanguage asp .net application using masterpages. > All the pages are derived from one class and the class has a function > which finds a specific label on the masterpage and prints the output > messages there. > > public void ShowMessage(string outputMessage) > { > Label lblOutput = (Label)Master.FindControl("lblMessage"); > lblOutput.Text = outputMessage; > } > > i have a string constants class and the strings with two languages are > definded there like this > > public struct InHouseMessages > { > public const string OPERATION_SUCCESS = "yehu"; > public const string OPERATION_SUCCESS_ENG = "yeah"; > public const string OPERATION_FAILURE = "nayir"; > public const string OPERATION_FAILURE_ENG = "damn"; > public const string OPERATION_STUCK = "hayiiiiiiirrr"; > public const string OPERATION_STUCK_ENG = "noooooooo"; > } > > What i want to do is make the ShowMessage function language aware like > this > > public void ShowMessage(string outputMessage, bool isENG) > { > if(isENG) > lblMessage.text = outputMessage+_ENG; > else > lblMessage.text = outputMessage; > } > > i mean i want to programmatically change the variable name befoure the > variable gets its string value. > Thank you for your help,
Firstly localization option would be a good way to go, but i have choosen the dictionary approach. The dictionary object seems to handle the job well. I created a class containing a dictioanry object which is declered as static and an ititializer function which is again static. in the global.asax file, applicationa start event, the inititalization function is called. Greg Young wrote: Show quote > Have you considerred storing these items as resources where they could be > easily localized (as opposed to trying to handle the localization on your > own)? > > http://www.codeproject.com/dotnet/Localization.asp is a quick example but if > you google on C# Resource Localiztion it should bring up a bunch of articles > for you. > > Cheers, > > Greg Young > <kaanen***@gmail.com> wrote in message > news:1148890764.007729.268010@y43g2000cwc.googlegroups.com... > > Hi, > > > > I am building a multilanguage asp .net application using masterpages. > > All the pages are derived from one class and the class has a function > > which finds a specific label on the masterpage and prints the output > > messages there. > > > > public void ShowMessage(string outputMessage) > > { > > Label lblOutput = (Label)Master.FindControl("lblMessage"); > > lblOutput.Text = outputMessage; > > } > > > > i have a string constants class and the strings with two languages are > > definded there like this > > > > public struct InHouseMessages > > { > > public const string OPERATION_SUCCESS = "yehu"; > > public const string OPERATION_SUCCESS_ENG = "yeah"; > > public const string OPERATION_FAILURE = "nayir"; > > public const string OPERATION_FAILURE_ENG = "damn"; > > public const string OPERATION_STUCK = "hayiiiiiiirrr"; > > public const string OPERATION_STUCK_ENG = "noooooooo"; > > } > > > > What i want to do is make the ShowMessage function language aware like > > this > > > > public void ShowMessage(string outputMessage, bool isENG) > > { > > if(isENG) > > lblMessage.text = outputMessage+_ENG; > > else > > lblMessage.text = outputMessage; > > } > > > > i mean i want to programmatically change the variable name befoure the > > variable gets its string value. > > My question would be what happenned when you needed a 3rd or 4th language.
<kaanen***@gmail.com> wrote in message Show quote news:1149062776.416741.114770@i40g2000cwc.googlegroups.com... > Thank you for your help, > > Firstly localization option would be a good way to go, but i have > choosen the dictionary approach. > The dictionary object seems to handle the job well. I created a class > containing a dictioanry object which is declered as static and an > ititializer function which is again static. > > in the global.asax file, applicationa start event, the inititalization > function is called. > > Greg Young wrote: >> Have you considerred storing these items as resources where they could be >> easily localized (as opposed to trying to handle the localization on your >> own)? >> >> http://www.codeproject.com/dotnet/Localization.asp is a quick example but >> if >> you google on C# Resource Localiztion it should bring up a bunch of >> articles >> for you. >> >> Cheers, >> >> Greg Young >> <kaanen***@gmail.com> wrote in message >> news:1148890764.007729.268010@y43g2000cwc.googlegroups.com... >> > Hi, >> > >> > I am building a multilanguage asp .net application using masterpages. >> > All the pages are derived from one class and the class has a function >> > which finds a specific label on the masterpage and prints the output >> > messages there. >> > >> > public void ShowMessage(string outputMessage) >> > { >> > Label lblOutput = (Label)Master.FindControl("lblMessage"); >> > lblOutput.Text = outputMessage; >> > } >> > >> > i have a string constants class and the strings with two languages are >> > definded there like this >> > >> > public struct InHouseMessages >> > { >> > public const string OPERATION_SUCCESS = "yehu"; >> > public const string OPERATION_SUCCESS_ENG = "yeah"; >> > public const string OPERATION_FAILURE = "nayir"; >> > public const string OPERATION_FAILURE_ENG = "damn"; >> > public const string OPERATION_STUCK = "hayiiiiiiirrr"; >> > public const string OPERATION_STUCK_ENG = "noooooooo"; >> > } >> > >> > What i want to do is make the ShowMessage function language aware like >> > this >> > >> > public void ShowMessage(string outputMessage, bool isENG) >> > { >> > if(isENG) >> > lblMessage.text = outputMessage+_ENG; >> > else >> > lblMessage.text = outputMessage; >> > } >> > >> > i mean i want to programmatically change the variable name befoure the >> > variable gets its string value. >> > > |
|||||||||||||||||||||||