This is a migrated thread and some comments may be shown as answers.

Localization vs. System.Threading.Thread.CurrentThread.CurrentUICulture

3 Answers 861 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Leoš
Top achievements
Rank 1
Leoš asked on 05 Nov 2012, 12:02 PM
Hi,

Why your controls does not respect this culture setting for localization: System.Threading.Thread.CurrentThread.CurrentUICulture? It is thread-wide culture for resources. I don't see any advantage of setting culture via Culture property of each control. We have multi-language application with hundereds of pages. It's impossible to set Culture declaratively in mark-up as well as in code behind for every single telerik control, unless we made our own ones inheriting from yours, but why? Is it possible to respect the CurrentUICulture, so that the default culture of each telerik control will be correct throughout the thread? Web.config setting is not a solution for us, because it would make a culture application-static. That is not a correct solution.

There is a method InitializeCulture of System.Web.UI.Page class, which is a part of page life-cycle. That is the place, where culture is being set for every request (meaning both Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture).
As far as HttpHandlers are concerned, ProcessRequest method should also contain culture initialization as one of the first things.

Thank you, best regards,
    Leos

3 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 05 Nov 2012, 03:38 PM
Hello Leos,

RadControls for ASP.NET AJAX do utilize the Culture and UICulture properties. You can find an example of various RadControls localization using GlobalResources in the following demo application:
 http://demos.telerik.com/aspnet-ajax/carrental/

Greetings,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Leoš
Top achievements
Rank 1
answered on 05 Nov 2012, 08:34 PM
Hello Dobromir,

I don't want to be rude, but that's actually not a response to my question. I am decently aware of Culture Property, though it might not have been obvious. I just would like to know how to make all Telerik controls respect ASP.NET standards and get their culture settings from CurrentThread settings, because that's the place, where to find current culture for currently processed thread. It is really not even thinkable to have 5 telerik controls on 200 pages (which makes 1000 instaces of controls) and to have to set their cultures via property of each control's instance. That leads to tons of code which in fact is NOT inevitable, because it is the responsibility of the control to set its default culture according to the CurrentThread Settings and not of the programmer, who uses a control. I want to avoid tons of code like this:

radGrid1.Culture = radGrid2.Culture = radDateTimePicker1.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture;

Even though I use global resources (disregarging resource provider), I still have to use Culture property, don't I? If a user is about to change culture dynamically while browsing my pages, placing a culture setting to a web.config is not a solution either. The only way I now know is through code-behind just because your controls does NOT set their cultures according to current culture of the current thread.

Or am I missing something?

Best regards,
    Leos
0
Leoš
Top achievements
Rank 1
answered on 06 Nov 2012, 09:10 AM
Long story short:

Instead of this:

public CultureInfo Culture
{
    get
    {
        return ((CultureInfo)this.ViewState["Culture"]) ?? CultureInfo.GetCultureInfo("en-US");
    }
    set
    {
        this.ViewState["Culture"] = value;
    }
}

You should use this:

public CultureInfo Culture
{
    get
    {
        return ((CultureInfo)this.ViewState["Culture"]) ?? System.Threading.Thread.CurrentThread.CurrentUICulture;
    }
    set
    {
        this.ViewState["Culture"] = value;
    }
}

Having looked at the codes, now it's just RadGrid, which returns CurrentUICulture. Other controls like RadAsyncUpload, RadProgressArea etc. returns "en-US" culture.

Best regards,
    Leos
Tags
General Discussions
Asked by
Leoš
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Leoš
Top achievements
Rank 1
Share this question
or