locked
Culture el-GR doesn't work RRS feed

  • Question

  • User-1883420192 posted

    Hello,

    I have a question about globalisation settings, I have an application which uses english language, but needs to have the Greek format for numbers and dates.

    When I set culture="el-GR" uiCulture="el-GR" (I set this in the globalization section of web.config and even in each page I use) I expect the dates in the application to be in the format we use in Greece (dd/MM/yyyy) and the amounts displayed with (,) for decimal places instead of period. But instead, the format returned is the same as en-US. When I change the format to spanish es-ES, the dates and decimal amounts are in the format I want.

    Does anyone have any idea why this doesnt work as it is supposed to?

    The other question is that if I use the spanish format, will I have any problems with my software? (I will get the dates and numbers displayed properly, but will the globalisation setting have any other effect in my application?

    Thanks,

    Emmanouil Filippou

    Saturday, January 16, 2010 6:38 AM

Answers

  • User-1636183269 posted

    Hello,

    If you are creating multilingual application then based on query string or session set value in Basepage. I have created one sample for you. One more thing date respective and currency respective it will handle automatically. But one thing you have to take care while display currency it will display in with "comma" but you have to take care when you enter into database then 1,00 will not accept by database due to may be you sql is en-Us format then in this case you have to explicitly transalte curency into 1.00. So it will work proper but if you will not take care then this amount will throw exception or will become 1000.00 in database. Just take care such thing rest of thing is fine.

    protected override void InitializeCulture()
            {

                // Based on Query string we set culture, else we set in web.congig as default country and language code

                //<add key="DefaultLanguageCode" value="EL" /> Based on our requirement we have set greek
                //<add key="DefaultCountryCode" value="GR" /> Based on our requirement we have set greek

                if (Request.QueryString.Count > 0)
                {
                    if (Request.QueryString["lang"] != null)
                    {
                        pLanguegeCode = Convert.ToString(Request.QueryString["lang"]);
                    }
                    else
                    {
                        if (ConfigurationManager.AppSettings["DefaultLanguageCode"] != null)
                        {
                            pLanguegeCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultLanguageCode"]);
                        }
                    }
                }
                
                if (ConfigurationManager.AppSettings["DefaultCountryCode"] != null)
                {
                    pCountryCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultCountryCode"]);
                }
                // based on language code we are setting Culture name
                if (pLanguegeCode.ToLower() == "en")
                {
                    Session["CultureName"] = "en-GB";
                }
                else if (pLanguegeCode.ToLower() == "el")
                {
                    Session["CultureName"] = "el-GR";
                }
                else
                {
                    Session["CultureName"] = "en-US";
                }
                if (Session["CultureName"] != null)
                {
                    string cultureName = Session["CultureName"].ToString();
                    //Change language setting to user-chosen one
                    if (cultureName != null)
                    {
                        //Set Culture
                        CultureInfo objCultureInfo = new CultureInfo(cultureName);
                        Thread.CurrentThread.CurrentUICulture = objCultureInfo;
                        
                        //Set Date Format as per your need
                        DateTimeFormatInfo objDateTimeFormatInfo = objCultureInfo.DateTimeFormat;
                        objDateTimeFormatInfo.ShortDatePattern = SetDateFormat();

                        //In web.config we set default date seprator, you can use . or \
                        //<add key ="DateSeparator" value ="/"/>
                        objDateTimeFormatInfo.DateSeparator = ConfigurationManager.AppSettings["DateSeparator"].ToString();
                        
                        objCultureInfo.DateTimeFormat = objDateTimeFormatInfo;

                        // Here specific culture will set
                        Thread.CurrentThread.CurrentCulture = objCultureInfo;
                        if (objDateTimeFormatInfo != null)
                            objDateTimeFormatInfo = null;
                        if (objCultureInfo != null) objCultureInfo = null;
                    }
                }
                
                base.InitializeCulture();
            }

            public string SetDateFormat()
            {
                string strFormat = "";
                //<add key ="DateFormat" value ="dd/MM/yyyy"/>
                if (ConfigurationManager.AppSettings["DateFormat"] == null)
                {
                    if (ConfigurationManager.AppSettings["DateSeparator"] == null)
                    {
                        strFormat = "MM/dd/yyyy";
                    }
                    else
                    {
                        //In web.config we set default date seprator, you can use . or \
                        //<add key ="DateSeparator" value ="/"/>
                        strFormat = "MM" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "dd" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "yyyy";
                    }
                }
                else
                {
                    //Based on culture it will set
                    strFormat = ConfigurationManager.AppSettings["DateFormat"].ToString(System.Globalization.CultureInfo.CurrentCulture);
                }

                return strFormat;
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 9:07 AM
  • User-1636183269 posted

    Hello efilippou,

    On my first sentence I had mentioned that set value

    in basepage, I want to say you please create one class

    give name as "BasePage" inherit from System.Web.UI.Page

    so all page you may inherit from BasePage instead  of 

    System.Web.UI.Page, so automatically culture respective

    property will set in basepage, so no duplication of code.

    First Sentence: If you are creating multilingual application then based on query string or session set value in Basepage.

    If you think that you don't need culture on some page then 

    call page from System.Web.UI.Page so your culture respective

    it will not override.

    Hello Das.Sandeep and thank you for the quick and VERY usefull reply!!

    Its more than what I was looking for... it now works as expected. It also gave me a good idea of what I need to do. 

    Do you think this is the best way to do what I need?
    This seems like a bug to me, because what we are really doing here is setting a custom date and time format, which should be done internally by the cultrure settings... right?

    Thanks for your time!

    I think first two question, I have replied.

    Now this one basically I have created on common function

    to format a date because. In my requirement "/" will be

    seprator and date format will be in two way if it is en-US

    then MM/dd/yyyy and if it is en-GB/it-IT/de-de then format

    will be dd/MM/yyyy. If you will not set culture in web.config

    then it will take defaul i.e en-US due to only it is working

    for spanish ( I assume spanish format is MM/dd/yyyy and it

    working not for default spanish it is working because default

    is en-US. I have created function because if any client will

    demand in format dd.MM.yyy or MM.dd.yyyy then for me it will

    be only configuration change instead of coding.

    Hope I am able to explain you, what you want. Please let me 

    know if you have any doubt.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 1:11 PM
  • User-1883420192 posted

    Problem partly found. It seems like the following function in my baseclass solves the problem

    Protected Overloads Overrides Sub InitializeCulture()
            Dim objCultureInfo As New CultureInfo("el-GR", False)
            Thread.CurrentThread.CurrentUICulture = objCultureInfo
            Thread.CurrentThread.CurrentCulture = objCultureInfo
            objCultureInfo = Nothing
            MyBase.InitializeCulture()
    End Sub 

    What that means is that I re-initialise the Greek culture settings to the default values (which is what this function does), instead of the user overrided values... so somewhere in my application something (probably a third party component) overrides the short date format to "M/d/yyyy"

    If anyone has any idea on how I can trace the culture changes (other than my visible code), please let me know...

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 5:04 PM
  • User-1636183269 posted

    Hello hoe,

    Hi, may be this's a stupid question, but what/where is the Basepage?

    Where should i include the codes?

    I have mention above respective to base page, basically it is custom class which I have inherited from System.Web.UI.Page. Please let me know if you have any dount. Mark as answer if it helps.

    "On my first sentence I had mentioned that set value

    in basepage, I want to say you please create one class

    give name as "BasePage" inherit from System.Web.UI.Page

    so all page you may inherit from BasePage instead  of 

    System.Web.UI.Page, so automatically culture respective

    property will set in basepage, so no duplication of code"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2010 1:38 AM

All replies

  • User-1636183269 posted

    Hello,

    If you are creating multilingual application then based on query string or session set value in Basepage. I have created one sample for you. One more thing date respective and currency respective it will handle automatically. But one thing you have to take care while display currency it will display in with "comma" but you have to take care when you enter into database then 1,00 will not accept by database due to may be you sql is en-Us format then in this case you have to explicitly transalte curency into 1.00. So it will work proper but if you will not take care then this amount will throw exception or will become 1000.00 in database. Just take care such thing rest of thing is fine.

    protected override void InitializeCulture()
            {

                // Based on Query string we set culture, else we set in web.congig as default country and language code

                //<add key="DefaultLanguageCode" value="EL" /> Based on our requirement we have set greek
                //<add key="DefaultCountryCode" value="GR" /> Based on our requirement we have set greek

                if (Request.QueryString.Count > 0)
                {
                    if (Request.QueryString["lang"] != null)
                    {
                        pLanguegeCode = Convert.ToString(Request.QueryString["lang"]);
                    }
                    else
                    {
                        if (ConfigurationManager.AppSettings["DefaultLanguageCode"] != null)
                        {
                            pLanguegeCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultLanguageCode"]);
                        }
                    }
                }
                
                if (ConfigurationManager.AppSettings["DefaultCountryCode"] != null)
                {
                    pCountryCode = Convert.ToString(ConfigurationManager.AppSettings["DefaultCountryCode"]);
                }
                // based on language code we are setting Culture name
                if (pLanguegeCode.ToLower() == "en")
                {
                    Session["CultureName"] = "en-GB";
                }
                else if (pLanguegeCode.ToLower() == "el")
                {
                    Session["CultureName"] = "el-GR";
                }
                else
                {
                    Session["CultureName"] = "en-US";
                }
                if (Session["CultureName"] != null)
                {
                    string cultureName = Session["CultureName"].ToString();
                    //Change language setting to user-chosen one
                    if (cultureName != null)
                    {
                        //Set Culture
                        CultureInfo objCultureInfo = new CultureInfo(cultureName);
                        Thread.CurrentThread.CurrentUICulture = objCultureInfo;
                        
                        //Set Date Format as per your need
                        DateTimeFormatInfo objDateTimeFormatInfo = objCultureInfo.DateTimeFormat;
                        objDateTimeFormatInfo.ShortDatePattern = SetDateFormat();

                        //In web.config we set default date seprator, you can use . or \
                        //<add key ="DateSeparator" value ="/"/>
                        objDateTimeFormatInfo.DateSeparator = ConfigurationManager.AppSettings["DateSeparator"].ToString();
                        
                        objCultureInfo.DateTimeFormat = objDateTimeFormatInfo;

                        // Here specific culture will set
                        Thread.CurrentThread.CurrentCulture = objCultureInfo;
                        if (objDateTimeFormatInfo != null)
                            objDateTimeFormatInfo = null;
                        if (objCultureInfo != null) objCultureInfo = null;
                    }
                }
                
                base.InitializeCulture();
            }

            public string SetDateFormat()
            {
                string strFormat = "";
                //<add key ="DateFormat" value ="dd/MM/yyyy"/>
                if (ConfigurationManager.AppSettings["DateFormat"] == null)
                {
                    if (ConfigurationManager.AppSettings["DateSeparator"] == null)
                    {
                        strFormat = "MM/dd/yyyy";
                    }
                    else
                    {
                        //In web.config we set default date seprator, you can use . or \
                        //<add key ="DateSeparator" value ="/"/>
                        strFormat = "MM" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "dd" + Convert.ToString(ConfigurationManager.AppSettings["DateSeparator"]) + "yyyy";
                    }
                }
                else
                {
                    //Based on culture it will set
                    strFormat = ConfigurationManager.AppSettings["DateFormat"].ToString(System.Globalization.CultureInfo.CurrentCulture);
                }

                return strFormat;
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 9:07 AM
  • User-1883420192 posted

    Hello Das.Sandeep and thank you for the quick and VERY usefull reply!!

    Its more than what I was looking for... it now works as expected. It also gave me a good idea of what I need to do. Following is my version, which is based on the idea that my application is not multilingual, it just needs these standard settings. And since I want this to be as fast as possible, I only implement the basic requirements.

    This is added in my basepage class:

        Protected Overloads Overrides Sub InitializeCulture()
            Dim objCultureInfo As New CultureInfo("el-GR")
            Thread.CurrentThread.CurrentUICulture = objCultureInfo

            Dim objDateTimeFormatInfo As DateTimeFormatInfo = objCultureInfo.DateTimeFormat
            objDateTimeFormatInfo.ShortDatePattern = "dd/MM/yy"
            objDateTimeFormatInfo.LongDatePattern = "dd/MM/yyyy"
            objCultureInfo.DateTimeFormat = objDateTimeFormatInfo
            objCultureInfo.NumberFormat.NumberGroupSeparator = "."
            objCultureInfo.NumberFormat.NumberDecimalSeparator = ","
            objCultureInfo.NumberFormat.NumberGroupSeparator = "."
            objCultureInfo.NumberFormat.CurrencyDecimalSeparator = ","
            objCultureInfo.NumberFormat.CurrencyGroupSeparator = "."
            objCultureInfo.NumberFormat.CurrencySymbol = "€"
            Thread.CurrentThread.CurrentCulture = objCultureInfo
            objDateTimeFormatInfo = Nothing
            objCultureInfo = Nothing
            MyBase.InitializeCulture()
        End Sub

    Do you think this is the best way to do what I need?

    I also have a few more questions:

    This is executed in every page call... I want my application to be as fast as it can possibly be, but it seems ackward that all these commands need to be executed for such a simple task...

    Why other cultures dont need this, like the spanish settings as I explained in my previous post? Especially since my windows regional settings have the greek formats set properly... Shouldnt these settings be applied by default when I set the globalization settings to greek?

    This seems like a bug to me, because what we are really doing here is setting a custom date and time format, which should be done internally by the cultrure settings... right?

    Thanks for your time!

    Saturday, January 16, 2010 11:26 AM
  • User-1636183269 posted

    Hello efilippou,

    On my first sentence I had mentioned that set value

    in basepage, I want to say you please create one class

    give name as "BasePage" inherit from System.Web.UI.Page

    so all page you may inherit from BasePage instead  of 

    System.Web.UI.Page, so automatically culture respective

    property will set in basepage, so no duplication of code.

    First Sentence: If you are creating multilingual application then based on query string or session set value in Basepage.

    If you think that you don't need culture on some page then 

    call page from System.Web.UI.Page so your culture respective

    it will not override.

    Hello Das.Sandeep and thank you for the quick and VERY usefull reply!!

    Its more than what I was looking for... it now works as expected. It also gave me a good idea of what I need to do. 

    Do you think this is the best way to do what I need?
    This seems like a bug to me, because what we are really doing here is setting a custom date and time format, which should be done internally by the cultrure settings... right?

    Thanks for your time!

    I think first two question, I have replied.

    Now this one basically I have created on common function

    to format a date because. In my requirement "/" will be

    seprator and date format will be in two way if it is en-US

    then MM/dd/yyyy and if it is en-GB/it-IT/de-de then format

    will be dd/MM/yyyy. If you will not set culture in web.config

    then it will take defaul i.e en-US due to only it is working

    for spanish ( I assume spanish format is MM/dd/yyyy and it

    working not for default spanish it is working because default

    is en-US. I have created function because if any client will

    demand in format dd.MM.yyy or MM.dd.yyyy then for me it will

    be only configuration change instead of coding.

    Hope I am able to explain you, what you want. Please let me 

    know if you have any doubt.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 1:11 PM
  • User-1883420192 posted

    In my application I already had a basepage which inherits from  System.Web.UI.Page, and of course there is no duplication of code... what I said is that this code executes everytime the basepage is called (which is in all my webpages)

    Also, as I said with the spanish settings (<globalization culture="el-GR" uiCulture="el-GR"/>), there is no need to have the extra code, because the date is displayed in the format I want which is dd/MM/yyyy and the amounts are displayed in the format I want... so I could just set the globalization paremeters for culture and uiculture within the web.config and everything works fine! No need for extra code to be executed, no extra overhead in the application performance!

    I tried to make a sample project for you to see, but when I tested it, I found that actually there must be something wrong with my application, because in the test application, just by setting the globalisation settings (<globalization culture="el-GR" uiCulture="el-GR"/>), I get what I expect, the proper number and date format!!

    So the question now is what could be the problem with my application and the Greek settings dont work, while the spanish settings work?? I looked everywhere within my application just in case I set a different culture setting, but I didnt find anything...

    Thanks for the valuable information!!!

     

    Saturday, January 16, 2010 1:37 PM
  • User-1883420192 posted

    Here is another indication of the problem

    The project I am having trouble with, has the following behaviour.
    I remove the custom culture settings, and set the following in web.config

    <globalization culture="el-GR" uiCulture="el-GR"  />

    Then, I check within a webpage the following properties:

    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern RETURNS "M/d/yyyy"
    Thread.CurrentThread.CurrentCulture.Name RETURNS "el-GR"

    Which is odd, since I am not changing anywhere in the application any culture settings other than the setting in web.config.

    Then I create a new web project, set in web.config the following again:
    <globalization culture="el-GR" uiCulture="el-GR"  />
    and check the properties in a page_load event:
    Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern RETURNS "d/M/yyyy"
    Thread.CurrentThread.CurrentCulture.Name RETURNS "el-GR"
    Which is the expected behaviour

    How can I find where does this setting get changed??? Any ideas?
    Is there a tool where I can trace the application to see where this change takes place?

    Thanks

    Saturday, January 16, 2010 3:25 PM
  • User-1883420192 posted

    Problem partly found. It seems like the following function in my baseclass solves the problem

    Protected Overloads Overrides Sub InitializeCulture()
            Dim objCultureInfo As New CultureInfo("el-GR", False)
            Thread.CurrentThread.CurrentUICulture = objCultureInfo
            Thread.CurrentThread.CurrentCulture = objCultureInfo
            objCultureInfo = Nothing
            MyBase.InitializeCulture()
    End Sub 

    What that means is that I re-initialise the Greek culture settings to the default values (which is what this function does), instead of the user overrided values... so somewhere in my application something (probably a third party component) overrides the short date format to "M/d/yyyy"

    If anyone has any idea on how I can trace the culture changes (other than my visible code), please let me know...

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 16, 2010 5:04 PM
  • User162937534 posted

    Hi, may be this's a stupid question, but what/where is the Basepage?

    Where should i include the codes?

    Thursday, February 4, 2010 12:38 AM
  • User-1636183269 posted

    Hello hoe,

    Hi, may be this's a stupid question, but what/where is the Basepage?

    Where should i include the codes?

    I have mention above respective to base page, basically it is custom class which I have inherited from System.Web.UI.Page. Please let me know if you have any dount. Mark as answer if it helps.

    "On my first sentence I had mentioned that set value

    in basepage, I want to say you please create one class

    give name as "BasePage" inherit from System.Web.UI.Page

    so all page you may inherit from BasePage instead  of 

    System.Web.UI.Page, so automatically culture respective

    property will set in basepage, so no duplication of code"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2010 1:38 AM
  • User522004677 posted

    Thank you guys, I think that I have enough info starting develop this. 

    Thursday, April 8, 2010 11:06 PM