ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • DateTime(날짜, 시간) 한국어로 변경하기
    Laravel/Nova 2022. 3. 19. 00:33
    반응형
    SMALL

    # What?

    라라벨 노바에서 쓰는 date filed 한국버전으로 변경

     

    # Why?

    -> IntlDatetime 라이브러리 안쓰는 이유? -> field로는 가능한데 filter에선 사용 불가능

     

    # How?

    페이지가 로딩되면 jquery로 텍스트만 바꿔주기(Jquery cdn 삽입)

     

    @ nova/resources/layout.blade

    ...
    <head>
            <script src="https://code.jquery.com/jquery-3.6.0.min.js"
                integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    </head>
    
    ...
    
    <script>
        Nova.liftOff()
    
        $(window).click(function(){
            if($(".flatpickr-monthDropdown-month").length > 0)
                changeDateLang();
        });
    
        setTimeout(function(){
            if($(".flatpickr-monthDropdown-month").length > 0)
                changeDateLang();
        }, 1000);
    
        function changeDateLang(){
            let text;
    
            let month = $(".flatpickr-monthDropdown-month");
    
            let weekdays = $(".flatpickr-weekdaycontainer").html();
    
            month.each(function(index, item){
                text = $(item).text();
    
                switch (text){
                    case "January":
                        $(item).text(text.replace("January", "01월"));
                        break;
                    case "February":
                        $(item).text(text.replace("February", "02월"));
                        break;
                    case "March":
                        $(item).text(text.replace("March", "03월"));
                        break;
                    case "April":
                        $(item).text(text.replace("April", "04월"));
                        break;
                    case "May":
                        $(item).text(text.replace("May", "05월"));
                        break;
                    case "June":
                        $(item).text(text.replace("June", "06월"));
                        break;
                    case "July":
                        $(item).text(text.replace("July", "07월"));
                        break;
                    case "August":
                        $(item).text(text.replace("August", "08월"));
                        break;
                    case "September":
                        $(item).text(text.replace("September", "09월"));
                        break;
                    case "October":
                        $(item).text(text.replace("October", "10월"));
                        break;
                    case "November":
                        $(item).text(text.replace("November", "11월"));
                        break;
                    case "December":
                        $(item).text(text.replace("December", "12월"));
                        break;
                }
    
            });
    
            weekdays = weekdays.replace("Sun", "일");
            weekdays = weekdays.replace("Mon", "월");
            weekdays = weekdays.replace("Tue", "화");
            weekdays = weekdays.replace("Wed", "수");
            weekdays = weekdays.replace("Thu", "목");
            weekdays = weekdays.replace("Fri", "금");
            weekdays = weekdays.replace("Sat", "토");
    
            $(".flatpickr-weekdaycontainer").html(weekdays);
        }
    </script>

     

    LIST

    댓글

Designed by Tistory.