Home All Groups Group Topic Archive Search About

dynamic variable naming

Author
29 May 2006 8:19 AM
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.

Author
29 May 2006 9:25 AM
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.

<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.
>
Author
29 May 2006 9:05 PM
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
<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.
>
Author
31 May 2006 8:06 AM
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.

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.
> >
Author
31 May 2006 11:16 PM
Greg Young
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.
>> >
>

AddThis Social Bookmark Button