diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts
index 71fd18d74..1e3de5b91 100644
--- a/docs/.vitepress/config.mts
+++ b/docs/.vitepress/config.mts
@@ -67,7 +67,7 @@ function nav() {
},
{
text: 'Roadmap',
- link: '/guide/roadmap'
+ link: '/guide/extra/roadmap'
},
{
text: 'v9.x',
@@ -90,17 +90,9 @@ function sidebarGuide() {
text: 'What is Vue I18n?',
link: '/guide/introduction'
},
- {
- text: 'Getting Started',
- link: '/guide/'
- },
{
text: 'Installation',
link: '/guide/installation'
- },
- {
- text: 'Roadmap',
- link: '/guide/roadmap'
}
]
},
@@ -108,6 +100,10 @@ function sidebarGuide() {
text: 'Essentials',
collapsible: true,
items: [
+ {
+ text: 'Getting Started',
+ link: '/guide/essentials/started',
+ },
{
text: 'Message Format Syntax',
link: '/guide/essentials/syntax'
@@ -217,13 +213,20 @@ function sidebarGuide() {
]
},
{
- text: 'v8.x',
+ text: 'Extra Topics',
collapsible: true,
- collapsed: true,
items: [
+ {
+ text: 'Different Distribution files',
+ link: '/guide/extra/dist'
+ },
{
text: 'Documentation for v8.x',
- link: '/guide/v8-docs'
+ link: '/guide/extra/v8-docs'
+ },
+ {
+ text: 'Roadmap',
+ link: '/guide/extra/roadmap'
}
]
}
diff --git a/docs/.vitepress/theme/styles/global.css b/docs/.vitepress/theme/styles/global.css
index 6516422db..8e4b7f7a6 100644
--- a/docs/.vitepress/theme/styles/global.css
+++ b/docs/.vitepress/theme/styles/global.css
@@ -1,10 +1,26 @@
:root {
+ --vp-c-brand-1: var(--vp-c-green-1);
+ --vp-c-brand-2: var(--vp-c-green-2);
+ --vp-c-brand-3: var(--vp-c-green-3);
+ --vp-c-brand-soft: var(--vp-c-green-soft);
+ --vp-code-color: #476582;
--vp-home-hero-name-color: transparent;
--vp-home-hero-image-filter: blur(72px);
--vp-home-hero-image-background-image: linear-gradient( -45deg, #647eff 30%, #42d392 );
--vp-home-hero-name-background: -webkit-linear-gradient(120deg, #647eff, #42d392);
}
+:root.dark {
+ --vp-code-color: #c9def1;
+
+ --vp-home-hero-image-filter: blur(72px);
+ --vp-home-hero-image-background-image: linear-gradient(
+ 0deg,
+ var(--vp-c-brand-soft) 50%,
+ var(--vp-c-brand-soft) 50%
+ );
+}
+
.vp-sponsor-grid.xmini .vp-sponsor-grid-link { height: 64px; }
.vp-sponsor-grid.xmini .vp-sponsor-grid-image { max-width: 64px; max-height: 22px }
diff --git a/docs/guide/advanced/composition.md b/docs/guide/advanced/composition.md
index 8d7f2ebcc..53f49311a 100644
--- a/docs/guide/advanced/composition.md
+++ b/docs/guide/advanced/composition.md
@@ -6,23 +6,31 @@ We have been describing the features of Vue I18n using the Legacy API, which is
## Basic Usage
-Let’s look at the basic usage of Vue I18n Composition API! Here we will learn the basic usage by modifying the code in [Getting Started](../../guide/) to learn the basic usage.
+Let’s look at the basic usage of Vue I18n Composition API! Here we will learn the basic usage by modifying the code in [Getting Started](../../guide/essentials/started) to learn the basic usage.
To compose with `useI18n` in `setup` of Vue 3, there is one thing you need to do, you need set the `legacy` option of the `createI18n` function to `false`.
The following is an example of adding the `legacy` option to `createI18n`:
-```js{5}
+```js{4}
// ...
-// 2. Create i18n instance with options
const i18n = VueI18n.createI18n({
- legacy: false, // you must set `false`, to use Composition API
- locale: 'ja', // set locale
- fallbackLocale: 'en', // set fallback locale
- messages, // set locale messages
- // If you need to specify other options, you can set other options
- // ...
+ legacy: false, // you must set `false`, to use Composition API // [!code ++]
+ locale: 'ja',
+ fallbackLocale: 'en',
+ messages: {
+ en: {
+ message: {
+ hello: 'hello world'
+ }
+ },
+ ja: {
+ message: {
+ hello: 'こんにちは、世界'
+ }
+ }
+ }
})
// ...
@@ -37,39 +45,42 @@ The following properties of i18n instance created by `createI18n` change its beh
- `global` property: VueI18n instance to Composer instance
:::
-You are now ready to use `useI18n` in the component `setup`. The code looks like this:
+You are now ready to use `useI18n` in the `App.vue` component. The code looks like this:
-```js{5-8}
-// ...
-
-// 3. Create a vue root instance
-const app = Vue.createApp({
- setup() {
- const { t } = VueI18n.useI18n() // call `useI18n`, and spread `t` from `useI18n` returning
- return { t } // return render context that included `t`
- }
-})
+```vue
+ // [!code ++]
-// ...
+
+
{{ $t("message.hello") }}
+
```
-You must call `useI18n` at top of the `setup`.
+You must call `useI18n` at top of the `
+
+
+
{{ $t("message.hello") }}
// [!code --]
+
{{ t("message.hello") }}
// [!code ++]
+
```
The output follows:
-```html{2}
+```vue
こんにちは、世界
@@ -81,7 +92,38 @@ In the Legacy API mode, the messages were translated using either `$t` or the Vu
In the Composition API mode, the Message Format Syntax remains the same as in the Legacy API mode. You can use the Composer instance `t` to translate a message as follows:
-```html
+```vue
+
+
{{ t('named', { msg }) }}
{{ t('list', [msg]) }}
@@ -89,42 +131,6 @@ In the Composition API mode, the Message Format Syntax remains the same as in th
{{ t('linked') }}
-
```
For more details of `t`, see the [API Reference](../../api/composition#t-key).
@@ -135,7 +141,22 @@ In the Legacy API mode, the plural form of the message was translated using eith
In the Composition API mode, the plural form of the message is left in syntax as in the Legacy API mode, but is translated using the `t` of the Composer instance:
-```html
+```vue
+
+
Car:
{{ t('car', 1) }}
@@ -150,27 +171,6 @@ In the Composition API mode, the plural form of the message is left in syntax as
{{ t('banana', 1) }}
{{ t('banana', { n: 'too many' }, 100) }}
-
-
```
:::tip NOTE
@@ -183,44 +183,39 @@ In the Legacy API mode, Datetime value was formatted using `$d` or the VueI18n i
In the Composition API mode, it uses the `d` of the Composer instance to format:
-```html
-
-
{{ t('current') }}: {{ d(now, 'long') }}
-
-
-
+
+
+
{{ t('current') }}: {{ d(now, 'long') }}
+
+
```
For more details of `d`, see the [API Reference](../../api/composition#d-value).
@@ -231,40 +226,34 @@ In the Legacy API mode, Number value is formatted using `$n` or the `n` of the V
In the Composition API mode, it is formatted using the `n` of the Composer instance:
-```html
-
-
{{ t('money') }}: {{ n(money, 'currency') }}
-
-
-
+
+
+
{{ t('money') }}: {{ n(money, 'currency') }}
+
```
For more details of `n`, see the [API Reference](../../api/composition#n-value).
@@ -279,20 +268,14 @@ There are two ways to refer the global scope Composer instance at the component.
### Explicit with `useI18n`
-As we have explained, `setup` in `useI18n` is a way.
+As we have explained, in `useI18n` is a way.
-```js
+```ts
import { useI18n } from 'vue-i18n'
-export default {
- setup() {
- const { t } = useI18n({ useScope: 'global' })
-
- // Something to do here ...
+const { t } = useI18n({ useScope: 'global' })
- return { t }
- }
-}
+// Something to do here ...
```
The above code sets the `useI18n` option to `useScope: 'global'`, which allows `useI18n` to return a Composer instance that can be accessed by the i18n instance `global` property. This allows `useI18n` to return the Composer instance that can be accessed by i18n instance`global` property, which is a global scope. The Composer instance is a global scope.
@@ -362,42 +345,36 @@ The following example codes:
```js
import { useI18n } from 'vue-i18n'
-export default {
- setup() {
- const { t, d, n, tm, locale } = useI18n({
- locale: 'ja-JP',
- fallbackLocale: 'en-US',
- messages: {
- 'en-US': {
- // ....
- },
- 'ja-JP': {
- // ...
- }
- },
- datetimeFormats: {
- 'en-US': {
- // ....
- },
- 'ja-JP': {
- // ...
- }
- },
- numberFormats: {
- 'en-US': {
- // ....
- },
- 'ja-JP': {
- // ...
- }
- }
- })
-
- // Something to do here ...
-
- return { t, d, n, tm, locale }
+const { t, d, n, tm, locale } = useI18n({
+ locale: 'ja-JP',
+ fallbackLocale: 'en-US',
+ messages: {
+ 'en-US': {
+ // ....
+ },
+ 'ja-JP': {
+ // ...
+ }
+ },
+ datetimeFormats: {
+ 'en-US': {
+ // ....
+ },
+ 'ja-JP': {
+ // ...
+ }
+ },
+ numberFormats: {
+ 'en-US': {
+ // ....
+ },
+ 'ja-JP': {
+ // ...
+ }
}
-}
+})
+
+// Something to do here ...
```
@@ -405,27 +382,21 @@ If you use i18n custom blocks in SFC as i18n resource of locale messages, it w
The following is an example of using i18n custom blocks and `useI18n` options:
-```html
-
@@ -443,21 +414,19 @@ In this example, the definition of resources is separated from i18n custom block
### Global Scope
-You want to change the locale with `setup`, just get a global Composer with `useI18n` and change it using the `locale` property of the instance.
-
-```js
-setup() {
- const { t, locale } = useI18n({ useScope: 'global' })
+You want to change the locale with `
```
And you can also use the setup context in the template, which can be changed as follows:
-```html
+```vue