mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 08:50:34 +01:00
@@ -60,7 +60,7 @@ import { fr } from '@nuxt/ui-pro/locale'
|
|||||||
|
|
||||||
### Custom locale
|
### Custom locale
|
||||||
|
|
||||||
You also have the option to add your own locale using `defineLocale`:
|
You can create your own locale using the `defineLocale` composable:
|
||||||
|
|
||||||
::module-only
|
::module-only
|
||||||
|
|
||||||
@@ -125,6 +125,65 @@ Look at the `code` parameter, there you need to pass the iso code of the languag
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
### Extend locale :badge{label="Soon" class="align-text-top"}
|
||||||
|
|
||||||
|
You can customize an existing locale by overriding its `messages` or `code` using the `extendLocale` composable:
|
||||||
|
|
||||||
|
::module-only
|
||||||
|
|
||||||
|
#ui
|
||||||
|
:::div
|
||||||
|
|
||||||
|
```vue [app.vue]
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { en } from '@nuxt/ui/locale'
|
||||||
|
|
||||||
|
const locale = extendLocale(en, {
|
||||||
|
code: 'en-GB',
|
||||||
|
messages: {
|
||||||
|
commandPalette: {
|
||||||
|
placeholder: 'Search a component...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UApp :locale="locale">
|
||||||
|
<NuxtPage />
|
||||||
|
</UApp>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
#ui-pro
|
||||||
|
:::div
|
||||||
|
|
||||||
|
```vue [app.vue]
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { en } from '@nuxt/ui-pro/locale'
|
||||||
|
|
||||||
|
const locale = extendLocale(en, {
|
||||||
|
code: 'en-GB',
|
||||||
|
messages: {
|
||||||
|
commandPalette: {
|
||||||
|
placeholder: 'Search a component...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UApp :locale="locale">
|
||||||
|
<NuxtPage />
|
||||||
|
</UApp>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
::
|
||||||
|
|
||||||
### Dynamic locale
|
### Dynamic locale
|
||||||
|
|
||||||
To dynamically switch between languages, you can use the [Nuxt I18n](https://i18n.nuxtjs.org/) module.
|
To dynamically switch between languages, you can use the [Nuxt I18n](https://i18n.nuxtjs.org/) module.
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ import { fr } from '@nuxt/ui-pro/locale'
|
|||||||
|
|
||||||
### Custom locale
|
### Custom locale
|
||||||
|
|
||||||
You also have the option to add your locale using `defineLocale`:
|
You can create your own locale using the `defineLocale` composable:
|
||||||
|
|
||||||
::module-only
|
::module-only
|
||||||
|
|
||||||
@@ -127,6 +127,67 @@ Look at the `code` parameter, there you need to pass the iso code of the languag
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
### Extend locale :badge{label="Soon" class="align-text-top"}
|
||||||
|
|
||||||
|
You can customize an existing locale by overriding its `messages` or `code` using the `extendLocale` composable:
|
||||||
|
|
||||||
|
::module-only
|
||||||
|
|
||||||
|
#ui
|
||||||
|
:::div
|
||||||
|
|
||||||
|
```vue [App.vue]
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { en } from '@nuxt/ui/locale'
|
||||||
|
import { extendLocale } from '@nuxt/ui/composables/defineLocale.js'
|
||||||
|
|
||||||
|
const locale = extendLocale(en, {
|
||||||
|
code: 'en-GB',
|
||||||
|
messages: {
|
||||||
|
commandPalette: {
|
||||||
|
placeholder: 'Search a component...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UApp :locale="locale">
|
||||||
|
<RouterView />
|
||||||
|
</UApp>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
#ui-pro
|
||||||
|
:::div
|
||||||
|
|
||||||
|
```vue [App.vue]
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { en } from '@nuxt/ui-pro/locale'
|
||||||
|
import { extendLocale } from '@nuxt/ui/composables/defineLocale.js'
|
||||||
|
|
||||||
|
const locale = extendLocale(en, {
|
||||||
|
code: 'en-GB',
|
||||||
|
messages: {
|
||||||
|
commandPalette: {
|
||||||
|
placeholder: 'Search a component...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UApp :locale="locale">
|
||||||
|
<RouterView />
|
||||||
|
</UApp>
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
::
|
||||||
|
|
||||||
### Dynamic locale
|
### Dynamic locale
|
||||||
|
|
||||||
To dynamically switch between languages, you can use the [Vue I18n](https://vue-i18n.intlify.dev/) plugin.
|
To dynamically switch between languages, you can use the [Vue I18n](https://vue-i18n.intlify.dev/) plugin.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import type { Locale, Direction } from '../types/locale'
|
import type { Locale, Direction } from '../types/locale'
|
||||||
|
import type { DeepPartial } from '../types/utils'
|
||||||
|
|
||||||
interface DefineLocaleOptions<M> {
|
interface DefineLocaleOptions<M> {
|
||||||
name: string
|
name: string
|
||||||
@@ -12,3 +13,8 @@ interface DefineLocaleOptions<M> {
|
|||||||
export function defineLocale<M>(options: DefineLocaleOptions<M>): Locale<M> {
|
export function defineLocale<M>(options: DefineLocaleOptions<M>): Locale<M> {
|
||||||
return defu<DefineLocaleOptions<M>, [{ dir: Direction }]>(options, { dir: 'ltr' })
|
return defu<DefineLocaleOptions<M>, [{ dir: Direction }]>(options, { dir: 'ltr' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* @__NO_SIDE_EFFECTS__ */
|
||||||
|
export function extendLocale<M>(locale: Locale<M>, options: Partial<DefineLocaleOptions<DeepPartial<M>>>): Locale<M> {
|
||||||
|
return defu<Locale<M>, [DefineLocaleOptions<M>]>(options, locale)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import type { VNode } from 'vue'
|
import type { VNode } from 'vue'
|
||||||
import type { AcceptableValue as _AcceptableValue } from 'reka-ui'
|
import type { AcceptableValue as _AcceptableValue } from 'reka-ui'
|
||||||
|
|
||||||
|
export type DeepPartial<T> = {
|
||||||
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] | undefined
|
||||||
|
}
|
||||||
|
|
||||||
export type DynamicSlotsKeys<Name extends string | undefined, Suffix extends string | undefined = undefined> = (
|
export type DynamicSlotsKeys<Name extends string | undefined, Suffix extends string | undefined = undefined> = (
|
||||||
Name extends string
|
Name extends string
|
||||||
? Suffix extends string
|
? Suffix extends string
|
||||||
|
|||||||
Reference in New Issue
Block a user