dynamic variable naming

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.
 
H

Hans Olav

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.
 
G

Greg Young

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
 
K

kaanengin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top