Custom String Format (internationalization)

5 posts, 0 answers
  1. MARIE
    MARIE avatar
    19 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

    Hi,
    You really help me in this thread http://www.telerik.com/community/forums/silverlight/pivotgrid/sum-of-timespan.aspx#2535687.

    Now I'm facing a new problem.

    I would like to display TimeSpan data like that: 1 day 11:22 or 2 days 01:01 or 1 jour 11:22, but I managed  only to display  in the singular form.

    Is there a best practice to format data as well?

    Regards,

    TB
  2. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 19 Mar 2013 Link to this post

    Hi Marie,

    In the project I've already sent you, there is a TimeSpanStringFormatSelector which is setting default string format. To achieve your desired output, you will have to modify the value there. For example the following code:
    format = aggregateDescription.StringFormat ?? @"dd' jour 'hh' : 'mm' : 'ss\.ffff";

    will create the following output (if the StringFormat is not set in the XAML or with the FieldList dialogs):
    01 jour 01 : 10 : 13.1231
    You can check here more details about TimeSpan string formats. Please note that you will have to escape (or put between '' symbols) all symbols which are not part of the default Format specifiers (intervals have to be escaped as well).

    Hopefully this helps. Feel free to contact us if you have any problems or concerns.

    Greetings,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. MARIE
    MARIE avatar
    19 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

    Hi again,
    Thanks for your answer but the real problem is to have the plural, I ought to use such a function.

    Is it possible to get the Timespan value?



    public static string TimeSpanToString(TimeSpan timespan)
            {
                if (timespan.Days == 0) // sans afficher le nombre de jour
                {
                    return timespan.ToString("hh\\:mm");
                }
                else if (timespan.Days == 1) // afficher jour avec internalisation
                {
                    StringBuilder l_timespanFormated = new StringBuilder();
                    l_timespanFormated.Append(string.Concat(timespan.Days.ToString(), " ", Resources.Languages.Interface.Jour));
                    l_timespanFormated.Append(timespan.ToString("\\ hh\\:mm"));
     
                    return l_timespanFormated.ToString();
                }
                else // afficher le nombre de jour avec internalisation
                {
                    StringBuilder l_timespanFormated = new StringBuilder();
                    if (timespan.Days < 0) return Resources.Languages.Interface.NonDisponible; //ce nombre ne peut être négatif
                    l_timespanFormated.Append(string.Concat(timespan.Days.ToString(), " ", Resources.Languages.Interface.Jours));
                    l_timespanFormated.Append(timespan.ToString("\\ hh\\:mm"));
     
                    return l_timespanFormated.ToString();
                }
            }


    Regards,

    TB
  5. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 19 Mar 2013 Link to this post

    Hello Marie,

    StringFormat is applied on all cells and it cannot be used to change the format based on the value. For this purpose you will have to use a new CellTemplate. We've implemented this scenario for you. I've also added a handler for PrepareDescriptionForField event of the DataProvider. With the code there, whenever you add the Time property to your Values box in RadPivotFieldList, a new TimeSpanAggregate description will be created.

    Hopefully this makes sense. Feel free to contact us if you still have any problems or concerns.

    Regards,
    Rosen Vladimirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. MARIE
    MARIE avatar
    19 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

    One word: brilliant!
Back to Top
DevCraft banner