본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

defineLocale 컴포저블

원문 보기 위키 갱신

defineLocale 컴포저블 (defineLocale)

앱에 맞춤 로케일(locale)을 만들기 위한 유틸리티예요. 자동으로 불러와지는 defineLocale 유틸리티를 사용해 자신만의 번역으로 로케일을 만들어 볼 수 있어요.

출처: Nuxt UI

본문

사용법 (Usage)

자동으로 import되는 defineLocale 유틸리티를 사용해 자신만의 번역으로 로케일을 만들어요.

<script setup lang="ts">
import type { Messages } from '@nuxt/ui'

const locale = defineLocale<Messages>({
  name: 'My custom locale',
  code: 'en',
  dir: 'ltr',
  messages: {
    // implement pairs
  }
})
</script>

<template>
  <UApp :locale="locale">
    <NuxtPage />
  </UApp>
</template>

Nuxt:

[!TIP] See: /docs/getting-started/integrations/i18n/nuxt

Learn more about internationalization in the i18n integration documentation.

[!TIP]

국제화(i18n)에 대한 자세한 내용은 i18n 통합 문서의 /docs/getting-started/integrations/i18n/nuxt 참고 자료를 확인해 보세요.

Vue:

[!TIP] See: /docs/getting-started/integrations/i18n/vue

Learn more about internationalization in the i18n integration documentation.

[!TIP]

국제화에 대한 자세한 내용은 i18n 통합 문서의 /docs/getting-started/integrations/i18n/vue 참고 자료를 확인해 보세요.

API

defineLocale<M>(options: DefineLocaleOptions<M>): Locale<M>

제공된 옵션으로 새로운 로케일 객체를 만들어요.

파라미터 (Parameters)

options (DefineLocaleOptions<M>) required: 다음 속성을 가진 로케일 설정 객체예요. 로케일의 표시 이름(예: 'English', 'Français'), 로케일의 ISO 코드(예: 'en', 'fr', 'de-AT'), 로케일의 텍스트 방향(기본값은 'ltr'), 번역 메시지 객체를 담아요. 타입 안전성을 위해 @nuxt/ui의 Messages 타입을 사용해요.

반환값 (Returns): App 컴포넌트의 locale prop에 전달할 수 있는 Locale<M> 객체를 반환해요.

예시 (Example)

맞춤 로케일을 만드는 전체 예시를 보여드릴게요.

<script setup lang="ts">
import type { Messages } from '@nuxt/ui'

const locale = defineLocale<Messages>({
  name: 'Español',
  code: 'es',
  dir: 'ltr',
  messages: {
    alert: {
      close: 'Cerrar'
    },
    modal: {
      close: 'Cerrar'
    },
    commandPalette: {
      back: 'Atrás',
      close: 'Cerrar',
      noData: 'Sin datos',
      noMatch: 'Sin resultados',
      placeholder: 'Escribe un comando o busca…'
    }
    // ... other component messages
  }
})
</script>

<template>
  <UApp :locale="locale">
    <NuxtPage />
  </UApp>
</template>

[!NOTE]

You can look at the built-in locales for reference on how to structure the messages object.

[!NOTE]

messages 객체를 어떻게 구성하는지는 내장 로케일을 참고 자료로 확인해 보세요.

사이트맵 (Sitemap)

전체 사이트맵에서 모든 페이지를 확인할 수 있어요.

더 알아보기 (Learn more)