Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Jensen 29 posts 160 karma points
    Feb 05, 2016 @ 08:05
    Daniel Jensen
    0

    Changing language for month names

    Hi, I want to print out the month names in a different language, than the default english. Im printing it out like this:

    @Umbraco.Content(item.Id).CreateDate.ToString("d. MMMM yyyy")
    

    But it will display it like this:

    1. January 2016

    I have tried doing this in my web.config file:

        <system.web>
           <globalization
             fileEncoding="utf-8"
             requestEncoding="utf-8"
             responseEncoding="utf-8"
             culture="da-DK"
             uiCulture="da-DK"
           />
        </system.web>
    

    But it does not change the output. Then i have tried doing this: enter image description here

    This works, so it reverts back to danish, but it seems like an odd way to change it. (what if it was a multilingual site?)

    Isn't there/shouldn't there be a way of telling Umbraco which to use as default? Or let it fall back on browser/web server defaults?

    Best regards Daniel

  • Daniel 60 posts 174 karma points
    Feb 05, 2016 @ 08:50
    Daniel
    1

    It might be as simple as this, haven't tried:

    @{
        var umbracoDate = Umbraco.Content(item.Id).CreateDate;
        var formattedDate = umbracoDate.ToString("d. MMMM yyyy", new CultureInfo("da-DK"));
        //you could always get the CultureInfo off CurrentCulture, but this is a nice test
    }
    @formattedDate
    
  • Kasper Holm 47 posts 180 karma points
    Feb 05, 2016 @ 09:01
    Kasper Holm
    101

    Hey Daniel

    Have you set a hostname and culture for your website ? :)

  • Daniel Jensen 29 posts 160 karma points
    Feb 05, 2016 @ 09:27
    Daniel Jensen
    1

    I was only checking up on this problem when i was running it on localhost (en-US OS), but I didn't think of checking our staging webserver, to see if it was present there. (which is set up correctly with hostname and culture)

    So it was indeed not a problem, when its hosted on a proper server, thanks Kasper Holm.

    new CultureInfo("da-DK")

    and

    CultureInfo.CurrentCulture

    Did indeed also do the trick :) Thanks Daniel

    Awesome cummunity again to the rescue :)

  • Kasper Holm 47 posts 180 karma points
    Feb 05, 2016 @ 10:01
    Kasper Holm
    0

    No problem had that issue loads of times ;)

Please Sign in or register to post replies

Write your reply to:

Draft