Changing culture at runtime

6 posts, 0 answers
  1. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 29 Oct 2015 Link to this post

    Hi,

     

    in our application we have the flexibility to change the culture at runtime and I would like to know if it's possible with Telerik?

     

    Thank'

    Alain

  2. Dinko
    Admin
    Dinko avatar
    201 posts

    Posted 03 Nov 2015 Link to this post

    Hello,

    Yes, it's possible to change the culture at runtime. You can set it programmatically.
    Thread.CurrentThread.CurrentCulture = new CultureInfo("de");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");
    You can read more about this in our Localization article.

    If you have any other questions, please don't hesitate to contact us again. 

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 03 Nov 2015 in reply to Dinko Link to this post

    Hi Dinko,

     

    this will change Telerik controls also (ie: RadScheduleView)???

     

    Thank's

    Alain

  5. Dinko
    Admin
    Dinko avatar
    201 posts

    Posted 06 Nov 2015 Link to this post

    Hello Alain,

    You can change the localization of RadScheduleView at runtime in a few steps. Firstly you can set the
    DefaultCulture property of the LocalizationManager to the new culture. Then you need to reset the template of the RadScheduleView control in order for the changes to take effect. For example:
    var cultureInfo = new CultureInfo("de-DE");
    LocalizationManager.DefaultCulture = cultureInfo;
    var myTemplate = this.MyScheduleView.Template;
    this.MyScheduleView.Template = null;
    this.MyScheduleView.Template = myTemplate;
    I have created a sample project using the code snippet above to see how you can implement the scenario.
    You can also check the Localization help article and demo.

    Hope this will help.

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 06 Nov 2015 in reply to Dinko Link to this post

    Great Dinko :)

     

    actually in our application we have multiple differents Telerik controls which can be created at the same time so I would like to know if it's possible when the localization of our application changeg, if I there is a way to search for all created Telerik controls an apply your logic to each one???

     

    Thank's

    Alain

  7. Dinko
    Admin
    Dinko avatar
    201 posts

    Posted 10 Nov 2015 Link to this post

    Hi Alain,

    You can change the localization of the Telerik controls at runtime in two ways. The first one is to set the static UseDynamicLocalization property of the LocalizationManager to true before calling the InitializeComponent() method of the application. This way when you change the localization manager's culture, the localized strings of the control will be updated. Keep in mind that this functionality is implemented only for part of our controls. For example, RadGridView and RadScheduleView won't work using this approach. The second one is to reset the template of the control as demonstrated in my previous answer. 

    To get all Telerik controls in your application, you can subscribe for their Loaded event using EventManager.RegisterClassHandler() method and store them in a collection. Then you can iterate through the collection and reset the templates of all it's elements.
    EventManager.RegisterClassHandler(typeof(Control), Control.LoadedEvent, new RoutedEventHandler(OnControlLoaded));
    Or you can use the ChildrenOfTypeExtensions.ChildrenOfType<T>() method to get all Telerik controls when you change the culture.

    Also, I have created a sample project with several Telerik controls where you can see how to implement these approaches. 

    Regards,
    Dinko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready