473,383 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

setting language/culture set the start of a page, rather than foreach date

I'm trying to create a multi-lingual ASP.NET (C#) page where text, etc
comes from a database, so that I don't have to maintain 6 copies of the
page. This is mostly working just fine, but I have a question about
displaying dates.

In ASP (original) I was able to SetLocale("fr-FR") or SetLocale("nl-NL")
at the start of the page based on an 'if' statement that determined
which language should be shown.

I understand that C# doesn't have "SetLocale", and that I need to
explore cultures. I found some code that might work, but had some questions:

Expand|Select|Wrap|Line Numbers
  1. CultureInfo myCulture = new CultureInfo("sl-SI", true);
  2. myCulture.DateTimeFormat.DateSeparator = "/";
  3. myCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
  4. DateTime date = DateTime.Parse(datestr, myCulture);
  5.  
- what namespace do I need for this to work?

- what other methods (? right term? kinda new to C#) can I add long side
DateSeparator and ShortDatePattern?

- can I set, via a 'switch' or 'if' different CultureInfo parameters? or
perhaps I can set a string to be "nl-NL" and use that as a parameter?

- is there a way to do with without using .Parse? Nothing against it,
just mostly curious

thanks

Kevin

Aug 23 '06 #1
2 1374

Kevin,

CultureInfo is part of the System.Globalization Namespace.

When you create a CultureInfo object like you have in your example,
"CultureInfo myCulture = new CultureInfo("sl-SI", true);" you already have
the correct date formats for Slovenian - Slovenia. You do not need to
specify your own.

To have the page use the culutre you would want to add a line similar to
System.Threading.Thread.CurrentThread.CurrentCultu re = myCulture;

You can use a switch statement to create the correct culture object and then
assing it to the current thread.

I'm not sure where the datestr variable comes from but
DateTime.Now.ToShortDateString might be what you are looking for since it
uses the CurrentCulture object for its output.

Hope this helps.

Michael

"Kevin Blount" wrote:
I'm trying to create a multi-lingual ASP.NET (C#) page where text, etc
comes from a database, so that I don't have to maintain 6 copies of the
page. This is mostly working just fine, but I have a question about
displaying dates.

In ASP (original) I was able to SetLocale("fr-FR") or SetLocale("nl-NL")
at the start of the page based on an 'if' statement that determined
which language should be shown.

I understand that C# doesn't have "SetLocale", and that I need to
explore cultures. I found some code that might work, but had some questions:

Expand|Select|Wrap|Line Numbers
  1. CultureInfo myCulture = new CultureInfo("sl-SI", true);
  2. myCulture.DateTimeFormat.DateSeparator = "/";
  3. myCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
  4. DateTime date = DateTime.Parse(datestr, myCulture);
  5.  

- what namespace do I need for this to work?

- what other methods (? right term? kinda new to C#) can I add long side
DateSeparator and ShortDatePattern?

- can I set, via a 'switch' or 'if' different CultureInfo parameters? or
perhaps I can set a string to be "nl-NL" and use that as a parameter?

- is there a way to do with without using .Parse? Nothing against it,
just mostly curious

thanks

Kevin

Aug 23 '06 #2
Thanks Michael, that did help :)

Michael wrote:
Kevin,

CultureInfo is part of the System.Globalization Namespace.

When you create a CultureInfo object like you have in your example,
"CultureInfo myCulture = new CultureInfo("sl-SI", true);" you already have
the correct date formats for Slovenian - Slovenia. You do not need to
specify your own.

To have the page use the culutre you would want to add a line similar to
System.Threading.Thread.CurrentThread.CurrentCultu re = myCulture;

You can use a switch statement to create the correct culture object and then
assing it to the current thread.

I'm not sure where the datestr variable comes from but
DateTime.Now.ToShortDateString might be what you are looking for since it
uses the CurrentCulture object for its output.

Hope this helps.

Michael

"Kevin Blount" wrote:
>I'm trying to create a multi-lingual ASP.NET (C#) page where text, etc
comes from a database, so that I don't have to maintain 6 copies of the
page. This is mostly working just fine, but I have a question about
displaying dates.

In ASP (original) I was able to SetLocale("fr-FR") or SetLocale("nl-NL")
at the start of the page based on an 'if' statement that determined
which language should be shown.

I understand that C# doesn't have "SetLocale", and that I need to
explore cultures. I found some code that might work, but had some questions:

Expand|Select|Wrap|Line Numbers
  1. CultureInfo myCulture = new CultureInfo("sl-SI", true);
  2. myCulture.DateTimeFormat.DateSeparator = "/";
  3. myCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
  4. DateTime date = DateTime.Parse(datestr, myCulture);

- what namespace do I need for this to work?

- what other methods (? right term? kinda new to C#) can I add long side
DateSeparator and ShortDatePattern?

- can I set, via a 'switch' or 'if' different CultureInfo parameters? or
perhaps I can set a string to be "nl-NL" and use that as a parameter?

- is there a way to do with without using .Parse? Nothing against it,
just mostly curious

thanks

Kevin

Aug 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
2
by: Hardy Wang | last post by:
Hi, We migrated some of web applications to a new server. When the server was installed, the regional setting was EN-CA, later on we found culture display was not same as from original server...
3
by: Reny J Joseph Thuthikattu | last post by:
Hi, If i put a month callender on a asp.net web form and specify the culture on the page directive like '<%@ Page language="c#" Culture="ar-OM"%> it will display the Month callender in arabic. ...
5
by: Robert W. | last post by:
My app runs perfectly when run in Canada or the U.S. But others are experiencing problems. So I switched my computer to the UK culture and immediately saw a problem. This line was failing: ...
2
by: Kevin Blount | last post by:
I'm trying to create a multi-lingual ASP.NET (C#) page where text, etc comes from a database, so that I don't have to maintain 6 copies of the page. This is mostly working just fine, but I have a...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: kidders | last post by:
Seem to be having problems with the en-GB culture/uiCulture setting, its making dates a format of the incorrect MM/dd/yyyy. I've searched the groups on this issue, here is a lengthy thread, where...
4
by: SevDer | last post by:
Hi, I've done some coding in my web application however right now for an unknown reason my asp.net 2.0 site is not setting asp.net_sessionid cookie and as a result, I am losing the session data...
5
by: Rajkiran R.B. | last post by:
Well I have multiple keyboard layouts installed in my system.. I have written a program in C# such that the required input language can be selected using the following piece of code ...
1
by: Marin | last post by:
I have some Calendar controls on my asp.net page. My computer (localhost) and my server is in Croatia, Europe. So calendar control have day in week and month caption on Croatian language. I want to...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.