dynamic variable naming

  • Thread starter Thread starter kaanengin
  • Start date Start date
K

kaanengin

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.
 
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.
 
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
 
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.
 
Back
Top