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

Custom localization

5 Answers 88 Views
TimeBar
This is a migrated thread and some comments may be shown as answers.
Philip
Top achievements
Rank 1
Philip asked on 09 Apr 2015, 10:36 AM

Hi, I want the time bar to show hours in European format (e.g 23 and not 11 PM).

The only way I found to achieve this is to set the global Telerik.Windows.Controls.LocalizationManager.DefaultCulture.

  1. 1. I tried to set Telerik.Windows.Controls.LocalizationManager.DefaultCulture to "de-DE". It removes AM/PM but does not change the number. So the range I get is 1-12 and not 0-23
  2. In our application we use a custom culture info, something like this
    cultureInfo = new CultureInfo("en-US");
    cultureInfo.NumberFormat = ...
    cultureInfo.DateTimeFormat.ShortDatePattern = ...

    What part of the cultureInfo is used to determine how hours are shown in time bar?
  3. I have similar issue with datetimepicker. How can i modify our culture info such that is uses 0-23 for hours instead of AM/PM (I see it has a property culture, so here I can just set "de-DE" as a workaround without effecting rest of application)

5 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 14 Apr 2015, 06:57 AM
Hello Philip,

The TimeBar and DateTimePicker use the culture for the current thread, as the localization mechanism allows you to localize any string resource used by the controls (e.g. Week => Woche, here you can find more about the localization in TimeBar). 

So, for your scenario I can suggest you the following: 
- if your current culture is English, you can use  Formatter Provider in the TimeBar to specify different formats for each interval (Hours 0-23 in your case). In our help topic Formatter Provider  you can see how to implement this feature;

- you can set German culture only to the DateTimePicker:
 
<telerik:RadDateTimePicker x:Name="radDateTimePicker" Culture="de"/>

or you can customize the DateTimeFormat (ShortTimePattern) of the current culture as it is shown in this article (if the last is applicable in your scenario - you said that you set CultureInfo.DateTimeFormat.ShortDatePattern).

Please let us know if this works for you. 

Regards,
Milena
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Philip
Top achievements
Rank 1
answered on 17 Apr 2015, 09:38 AM

Hi, thanks for the reply.

Using Formatter Provider for TimeBar and specifying ShortDatePattern solves my problems. (realized specifying Culture="de" was not what I wanted, since I wanted to keep the names of days in English).

 

However I still don't fully understand the IIntervalFormatterProvider interface :

1. GetFormatters returns a list for functions. How does Telerik decide which ones to use?

2. In my application, it seems the function returned by GetIntervalSpanFormatters is never used. For me this is fine, but when does telerik try to use these functions? The example says its when CurrentIntervalSpan = 12, but what makes CurrentIntervalSpan change?

Can GetIntervalSpanformatters return an empty list?

0
Milena
Telerik team
answered on 20 Apr 2015, 12:39 PM
Hi Philip,

Basically, TimeBar calculates the size of the labels and determines on each resize/zoom operation which view is the best current view, depending on the Intervals collection and the available size. The control always try to set the most detailed information, e.g. if you have set WeekInterval, HourInterval, MinuteInterval, the TimeBar will try to show the minutes if this is possible.

So, back to your questions: 
1.GetFormatters returns a list for function - in our case in HourFormatterProvider() we have set 2 dates: 
static HourFormatterProvider()
  {
      formatters = new Func<DateTime, string>[]
      {
          date => date.ToString("H:mm"),
          date => date.ToString("HH")
      };
  }

So, if it is possible, the TimeBar will show more detailed format (hours and minutes "H:mm") and if there is not enough space - just hours.

2.  GetIntervalSpanFormatters is used when one period control corresponds to a couple of interval items. For instance if you set the IntervalSpans property: 
<telerik:RadTimeBar.Intervals>
  <telerik:HourInterval FormatterProvider="{StaticResource HourFormatterProvider}" IntervalSpans="1,12"/>
</telerik:RadTimeBar.Intervals>

So, again depending on the available size and visible range the hours intervals would be (0:00 - 12:00) and (12:00 - 0:00) or 0:00, 1:00. By default the value of IntervalSpans is 1.

I hope this information helps. Please don't hesitate to write us back if you have more questions.

Regards,
Milena
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Philip
Top achievements
Rank 1
answered on 20 Apr 2015, 12:46 PM

1. Will the order of functions returned by GetFormatters matter? Or does telerik measure the size of the resulting strings to decide which one fits

 2. Can GetIntervalSpanFormatters return an empty list if I keep the property InervalsSpans unchanged (so it is 1)?

0
Accepted
Milena
Telerik team
answered on 21 Apr 2015, 07:55 AM
Hello Philip,

Let me get straight to your questions: 
1) Yes, the order of formatters has matter - the first has the highest priority, so when you define the formatters you should set the most detailed at first position if there is not a big difference in their length. You can try this by changing the places of the dates in HourFormatterProvider() or set some longer hour format and observe the behavior.
2) As I said the default value of the IntervalSpans is 1, so you cannot return an empty list, this will lead to an exception. 
If you are interesting, you can take a look at the source of the TimeBar control and the implementation of IIntervalFormatterProvider interface, which is in DataVisualization project => TimeBar => Intervals.

Let us know if there is anything else we can assist you with.
 
Regards,
Milena
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
TimeBar
Asked by
Philip
Top achievements
Rank 1
Answers by
Milena
Telerik team
Philip
Top achievements
Rank 1
Share this question
or