Skip to content

Latest commit

 

History

History
150 lines (113 loc) · 4.14 KB

I18n.md

File metadata and controls

150 lines (113 loc) · 4.14 KB

Notice

The document here no longer updates.

Please visit our website https://day.js.org for more information.












Internationalization

Day.js는 많은 다국어를 지원합니다.

다국어 설정은 추가로 설정을 해주어야 합니다.

Day.js에서 기본 locale 값은 영어(미국) 입니다.

여러 locale을 로드하고 쉽게 전환할 수 있습니다.

지원하는 locale 목록

풀 리퀘스트를 열어 당신의 locale을 추가할 수 있습니다. 👍

API

Changing locale globally

  • locale 문자열로 반환합니다.
import 'dayjs/locale/es'
import de from 'dayjs/locale/de'
dayjs.locale('es') // 글로벌 하게 locale을 로드하여 사용합니다.
dayjs.locale('de-german', de) // locale 사용 및 기본 이름 문자열 업데이트
const customizedLocaleObject = { ... } // 자세한 내용은 아래 커스텀 설정 섹션을 참조하세요.
dayjs.locale(customizedLocaleObject) // 커스텀 locale 사용
dayjs.locale('en') // switch back to default English locale globally
  • 글로벌 locale을 변경해도 기존 인스턴스에는 영향을 주지 않습니다.

Changing locales locally

  • 새로운 locale로 전환하여 새로운 'Dayjs' 오브젝트를 반환합니다.

정확히 dayjs#locale과 동일하지만, 특정 인스턴스에서만 locale을 사용합니다.

import 'dayjs/locale/es'
dayjs()
  .locale('es')
  .format() // 국지적으로 locale을 로드하여 사용합니다..
dayjs('2018-4-28', { locale: 'es' }) // through constructor

Installation

  • NPM:
import 'dayjs/locale/es' // load on demand
// require('dayjs/locale/es') // CommonJS
// import locale_es from 'dayjs/locale/es' -> load and get locale_es locale object

dayjs.locale('es') // 글로벌 하게 사용
dayjs()
  .locale('es')
  .format() // 특정 인스턴스에서 사용.
  • CDN:
<script src="https://unpkg.com/dayjs"></script>
<!-- Load locale as window.dayjs_locale_NAME -->
<script src="https://unpkg.com/dayjs/locale/zh-cn"></script>
<script>
  dayjs.locale('zh-cn')
  dayjs()
    .locale('zh-cn')
    .format()
  // get locale object
  const customLocale = window.dayjs_locale_zh_cn // zh-cn -> zh_cn
</script>

Customize

You could update locale config via plugin UpdateLocale

당신만의 locale을 만들 수 있습니다.

locale을 공휴하기위해 풀 리퀘스트를 여십시오.

Day.js locale 오브젝트 템플릿 입니다.

const localeObject = {
  name: 'es', // name String
  weekdays: 'Domingo_Lunes ...'.split('_'), // weekdays Array
  weekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not provided
  weekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not provided
  weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。
  yearStart: 4, // OPTIONAL, the week that contains Jan 4th is the first week of the year.
  months: 'Enero_Febrero ... '.split('_'), // months Array
  monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
  ordinal: n => `${n}º`, // ordinal Function (number) => return number + output
  relativeTime = { // relative time format strings, keep %s %d as the same
    future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours
    past: '%s ago',
    s: 'a few seconds',
    m: 'a minute',
    mm: '%d minutes',
    h: 'an hour',
    hh: '%d hours', // e.g. 2 hours, %d been replaced with 2
    d: 'a day',
    dd: '%d days',
    M: 'a month',
    MM: '%d months',
    y: 'a year',
    yy: '%d years'
  },
  meridiem: (hour, minute, isLowercase) => {
    // OPTIONAL, AM/PM
    return hour > 12 ? 'PM' : 'AM'
  }
}

Day.js locale 파일 템플릿 입니다.

import dayjs from 'dayjs'

const locale = { ... } // Your Day.js locale Object.

dayjs.locale(locale, null, true) // load locale for later use

export default locale