@intlayer/docs 7.3.11 → 7.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_nuxt.md +305 -421
- package/docs/ar/intlayer_with_react_router_v7.md +33 -4
- package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/ar/intlayer_with_tanstack.md +2 -12
- package/docs/ar/intlayer_with_vite+vue.md +1 -0
- package/docs/de/intlayer_with_nuxt.md +296 -394
- package/docs/de/intlayer_with_react_router_v7.md +33 -4
- package/docs/de/intlayer_with_react_router_v7_fs_routes.md +573 -0
- package/docs/de/intlayer_with_tanstack.md +1 -0
- package/docs/de/intlayer_with_vite+vue.md +1 -0
- package/docs/en/intlayer_with_nuxt.md +242 -321
- package/docs/en/intlayer_with_react_router_v7.md +24 -0
- package/docs/en/intlayer_with_react_router_v7_fs_routes.md +570 -0
- package/docs/en/intlayer_with_tanstack.md +2 -12
- package/docs/en/intlayer_with_vite+vue.md +49 -48
- package/docs/en-GB/intlayer_with_nuxt.md +262 -358
- package/docs/en-GB/intlayer_with_react_router_v7.md +33 -4
- package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +513 -0
- package/docs/en-GB/intlayer_with_tanstack.md +2 -12
- package/docs/en-GB/intlayer_with_vite+vue.md +1 -0
- package/docs/es/intlayer_with_nuxt.md +284 -375
- package/docs/es/intlayer_with_react_router_v7.md +33 -4
- package/docs/es/intlayer_with_react_router_v7_fs_routes.md +575 -0
- package/docs/es/intlayer_with_tanstack.md +1 -0
- package/docs/es/intlayer_with_vite+vue.md +1 -2
- package/docs/fr/intlayer_with_nuxt.md +288 -387
- package/docs/fr/intlayer_with_react_router_v7.md +34 -5
- package/docs/fr/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/fr/intlayer_with_tanstack.md +1 -0
- package/docs/fr/intlayer_with_vite+vue.md +1 -0
- package/docs/hi/intlayer_with_nuxt.md +318 -434
- package/docs/hi/intlayer_with_react_router_v7.md +33 -4
- package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +518 -0
- package/docs/hi/intlayer_with_tanstack.md +2 -12
- package/docs/hi/intlayer_with_vite+vue.md +1 -0
- package/docs/id/intlayer_with_nuxt.md +275 -376
- package/docs/id/intlayer_with_react_router_v7.md +29 -4
- package/docs/id/intlayer_with_react_router_v7_fs_routes.md +521 -0
- package/docs/id/intlayer_with_tanstack.md +2 -12
- package/docs/id/intlayer_with_vite+vue.md +1 -0
- package/docs/it/intlayer_with_nuxt.md +312 -408
- package/docs/it/intlayer_with_react_router_v7.md +33 -4
- package/docs/it/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/it/intlayer_with_tanstack.md +1 -0
- package/docs/ja/intlayer_with_nuxt.md +319 -414
- package/docs/ja/intlayer_with_react_router_v7.md +33 -4
- package/docs/ja/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ja/intlayer_with_tanstack.md +2 -12
- package/docs/ja/intlayer_with_vite+vue.md +1 -0
- package/docs/ko/intlayer_with_nuxt.md +307 -406
- package/docs/ko/intlayer_with_react_router_v7.md +33 -4
- package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +515 -0
- package/docs/ko/intlayer_with_tanstack.md +2 -12
- package/docs/ko/intlayer_with_vite+vue.md +1 -0
- package/docs/pl/intlayer_with_nuxt.md +282 -457
- package/docs/pl/intlayer_with_react_router_v7.md +32 -5
- package/docs/pl/intlayer_with_react_router_v7_fs_routes.md +615 -0
- package/docs/pl/intlayer_with_tanstack.md +2 -12
- package/docs/pl/intlayer_with_vite+vue.md +1 -0
- package/docs/pt/intlayer_with_nuxt.md +288 -403
- package/docs/pt/intlayer_with_react_router_v7.md +28 -0
- package/docs/pt/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_nuxt.md +300 -410
- package/docs/ru/intlayer_with_react_router_v7.md +33 -4
- package/docs/ru/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ru/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_vite+vue.md +1 -0
- package/docs/tr/intlayer_with_nuxt.md +327 -392
- package/docs/tr/intlayer_with_react_router_v7.md +33 -4
- package/docs/tr/intlayer_with_react_router_v7_fs_routes.md +572 -0
- package/docs/tr/intlayer_with_tanstack.md +2 -12
- package/docs/tr/intlayer_with_vite+vue.md +1 -0
- package/docs/vi/intlayer_with_nuxt.md +282 -399
- package/docs/vi/intlayer_with_react_router_v7.md +29 -4
- package/docs/vi/intlayer_with_react_router_v7_fs_routes.md +523 -0
- package/docs/vi/intlayer_with_tanstack.md +2 -12
- package/docs/vi/intlayer_with_vite+vue.md +1 -0
- package/docs/zh/intlayer_with_nuxt.md +311 -444
- package/docs/zh/intlayer_with_react_router_v7.md +33 -4
- package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/zh/intlayer_with_tanstack.md +2 -12
- package/docs/zh/intlayer_with_vite+vue.md +1 -0
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +19 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-06-18
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title: Cách dịch ứng dụng Nuxt và Vue của bạn –
|
|
3
|
+
updatedAt: 2025-12-07
|
|
4
|
+
title: Cách dịch ứng dụng Nuxt và Vue của bạn – Hướng dẫn i18n 2025
|
|
5
5
|
description: Khám phá cách làm cho trang web Nuxt và Vue của bạn đa ngôn ngữ. Theo dõi tài liệu để quốc tế hóa (i18n) và dịch nó.
|
|
6
6
|
keywords:
|
|
7
7
|
- Quốc tế hóa
|
|
@@ -14,8 +14,12 @@ slugs:
|
|
|
14
14
|
- doc
|
|
15
15
|
- environment
|
|
16
16
|
- nuxt-and-vue
|
|
17
|
-
applicationTemplate: https://github.com/aymericzip/intlayer-nuxt-template
|
|
17
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-nuxt-4-template
|
|
18
|
+
youtubeVideo: https://www.youtube.com/watch?v=IE3XWkZ6a5U
|
|
18
19
|
history:
|
|
20
|
+
- version: 7.3.11
|
|
21
|
+
date: 2025-12-07
|
|
22
|
+
changes: Cập nhật LocaleSwitcher, SEO, metadata
|
|
19
23
|
- version: 5.5.10
|
|
20
24
|
date: 2025-06-29
|
|
21
25
|
changes: Khởi tạo lịch sử
|
|
@@ -23,8 +27,6 @@ history:
|
|
|
23
27
|
|
|
24
28
|
# Dịch trang web Nuxt và Vue của bạn bằng Intlayer | Quốc tế hóa (i18n)
|
|
25
29
|
|
|
26
|
-
Xem [Application Template](https://github.com/aymericzip/intlayer-nuxt-template) trên GitHub.
|
|
27
|
-
|
|
28
30
|
## Mục lục
|
|
29
31
|
|
|
30
32
|
<TOC/>
|
|
@@ -35,9 +37,9 @@ Xem [Application Template](https://github.com/aymericzip/intlayer-nuxt-template)
|
|
|
35
37
|
|
|
36
38
|
Với Intlayer, bạn có thể:
|
|
37
39
|
|
|
38
|
-
- **
|
|
39
|
-
- **Đị
|
|
40
|
-
- **Đảm bảo hỗ trợ TypeScript** với các kiểu tự động tạo, cải thiện
|
|
40
|
+
- **Quản lý bản dịch dễ dàng** bằng cách sử dụng từ điển khai báo ở cấp độ component.
|
|
41
|
+
- **Địa phương hóa động metadata**, các route và nội dung.
|
|
42
|
+
- **Đảm bảo hỗ trợ TypeScript** với các kiểu tự động tạo, cải thiện việc tự động hoàn thành và phát hiện lỗi.
|
|
41
43
|
- **Tận hưởng các tính năng nâng cao**, như phát hiện và chuyển đổi locale động.
|
|
42
44
|
|
|
43
45
|
---
|
|
@@ -45,7 +47,7 @@ Với Intlayer, bạn có thể:
|
|
|
45
47
|
## Hướng dẫn từng bước để thiết lập Intlayer trong ứng dụng Nuxt
|
|
46
48
|
|
|
47
49
|
<iframe
|
|
48
|
-
src="https://stackblitz.com/github/aymericzip/intlayer-nuxt-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
50
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-nuxt-4-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
49
51
|
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
50
52
|
title="Demo CodeSandbox - Cách quốc tế hóa ứng dụng của bạn bằng Intlayer"
|
|
51
53
|
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
@@ -54,6 +56,27 @@ Với Intlayer, bạn có thể:
|
|
|
54
56
|
|
|
55
57
|
### Bước 1: Cài đặt các phụ thuộc
|
|
56
58
|
|
|
59
|
+
<Tab defaultTab="video">
|
|
60
|
+
<TabItem label="Video" value="video">
|
|
61
|
+
|
|
62
|
+
<iframe title="Cách dịch ứng dụng Nuxt và Vue của bạn bằng Intlayer? Khám phá Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/IE3XWkZ6a5U?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
63
|
+
|
|
64
|
+
</TabItem>
|
|
65
|
+
<TabItem label="Mã nguồn" value="code">
|
|
66
|
+
|
|
67
|
+
<iframe
|
|
68
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-nuxt-4-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
69
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
70
|
+
title="Demo CodeSandbox - Cách quốc tế hóa ứng dụng của bạn bằng Intlayer"
|
|
71
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
72
|
+
loading="lazy"
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
</TabItem>
|
|
76
|
+
</Tab>
|
|
77
|
+
|
|
78
|
+
Xem [Application Template](https://github.com/aymericzip/intlayer-nuxt-4-template) trên GitHub.
|
|
79
|
+
|
|
57
80
|
Cài đặt các gói cần thiết bằng npm:
|
|
58
81
|
|
|
59
82
|
```bash packageManager="npm"
|
|
@@ -73,17 +96,17 @@ yarn add --save-dev nuxt-intlayer
|
|
|
73
96
|
|
|
74
97
|
- **intlayer**
|
|
75
98
|
|
|
76
|
-
Gói cốt lõi cung cấp các công cụ quốc tế hóa cho quản lý cấu hình, dịch thuật, [khai báo nội dung](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/dictionary/content_file.md), biên dịch lại, và
|
|
99
|
+
Gói cốt lõi cung cấp các công cụ quốc tế hóa cho quản lý cấu hình, dịch thuật, [khai báo nội dung](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/dictionary/content_file.md), biên dịch lại, và các [lệnh CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/cli/index.md).
|
|
77
100
|
|
|
78
101
|
- **vue-intlayer**
|
|
79
102
|
Gói tích hợp Intlayer với ứng dụng Vue. Nó cung cấp các composables cho các component Vue.
|
|
80
103
|
|
|
81
104
|
- **nuxt-intlayer**
|
|
82
|
-
|
|
105
|
+
Mô-đun Nuxt tích hợp Intlayer với các ứng dụng Nuxt. Nó cung cấp thiết lập tự động, middleware để phát hiện locale, quản lý cookie, và chuyển hướng URL.
|
|
83
106
|
|
|
84
107
|
### Bước 2: Cấu hình dự án của bạn
|
|
85
108
|
|
|
86
|
-
Tạo một file cấu hình để cấu hình các ngôn ngữ
|
|
109
|
+
Tạo một file cấu hình để cấu hình các ngôn ngữ của ứng dụng của bạn:
|
|
87
110
|
|
|
88
111
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
89
112
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
@@ -98,9 +121,6 @@ const config: IntlayerConfig = {
|
|
|
98
121
|
],
|
|
99
122
|
defaultLocale: Locales.ENGLISH,
|
|
100
123
|
},
|
|
101
|
-
content: {
|
|
102
|
-
contentDir: ["."], // Vì mặc định Intlayer sẽ theo dõi các file khai báo nội dung từ thư mục `./src`
|
|
103
|
-
},
|
|
104
124
|
};
|
|
105
125
|
|
|
106
126
|
export default config;
|
|
@@ -120,9 +140,6 @@ const config = {
|
|
|
120
140
|
],
|
|
121
141
|
defaultLocale: Locales.ENGLISH,
|
|
122
142
|
},
|
|
123
|
-
content: {
|
|
124
|
-
contentDir: ["."],
|
|
125
|
-
},
|
|
126
143
|
};
|
|
127
144
|
|
|
128
145
|
export default config;
|
|
@@ -142,17 +159,14 @@ const config = {
|
|
|
142
159
|
],
|
|
143
160
|
defaultLocale: Locales.ENGLISH,
|
|
144
161
|
},
|
|
145
|
-
content: {
|
|
146
|
-
contentDir: ["."],
|
|
147
|
-
},
|
|
148
162
|
};
|
|
149
163
|
|
|
150
164
|
module.exports = config;
|
|
151
165
|
```
|
|
152
166
|
|
|
153
|
-
> Thông qua tệp cấu hình này, bạn có thể thiết lập URL
|
|
167
|
+
> Thông qua tệp cấu hình này, bạn có thể thiết lập các URL địa phương hóa, chuyển hướng middleware, tên cookie, vị trí và phần mở rộng của các khai báo nội dung của bạn, tắt các log của Intlayer trên console, và nhiều hơn nữa. Để xem danh sách đầy đủ các tham số có sẵn, hãy tham khảo [tài liệu cấu hình](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/configuration.md).
|
|
154
168
|
|
|
155
|
-
### Bước 3: Tích hợp Intlayer vào
|
|
169
|
+
### Bước 3: Tích hợp Intlayer vào cấu hình Nuxt của bạn
|
|
156
170
|
|
|
157
171
|
Thêm module intlayer vào cấu hình Nuxt của bạn:
|
|
158
172
|
|
|
@@ -165,221 +179,37 @@ export default defineNuxtConfig({
|
|
|
165
179
|
});
|
|
166
180
|
```
|
|
167
181
|
|
|
168
|
-
> Module `nuxt-intlayer` tự động xử lý việc tích hợp Intlayer với Nuxt. Nó thiết lập việc xây dựng khai báo nội dung,
|
|
182
|
+
> Module `nuxt-intlayer` tự động xử lý việc tích hợp Intlayer với Nuxt. Nó thiết lập việc xây dựng khai báo nội dung, giám sát các tệp trong chế độ phát triển, cung cấp middleware để phát hiện locale, và quản lý định tuyến theo locale.
|
|
169
183
|
|
|
170
184
|
### Bước 4: Khai báo Nội dung của Bạn
|
|
171
185
|
|
|
172
|
-
Tạo và quản lý các khai báo nội dung để lưu trữ
|
|
186
|
+
Tạo và quản lý các khai báo nội dung để lưu trữ bản dịch:
|
|
173
187
|
|
|
174
|
-
```tsx fileName="
|
|
175
|
-
import {
|
|
188
|
+
```tsx fileName="content/home-page.content.ts" contentDeclarationFormat="typescript"
|
|
189
|
+
import { type Dictionary, t } from "intlayer";
|
|
176
190
|
|
|
177
|
-
const
|
|
178
|
-
key: "
|
|
191
|
+
const content = {
|
|
192
|
+
key: "home-page",
|
|
179
193
|
content: {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
185
|
-
}),
|
|
186
|
-
checkOut: t({ en: "Check out ", fr: "Vérifiez ", es: "Compruebe " }),
|
|
187
|
-
nuxtIntlayer: t({
|
|
188
|
-
en: "Nuxt Intlayer documentation",
|
|
189
|
-
fr: "Documentation de Nuxt Intlayer",
|
|
190
|
-
es: "Documentación de Nuxt Intlayer",
|
|
191
|
-
}),
|
|
192
|
-
learnMore: t({
|
|
193
|
-
en: "Learn more about Nuxt in the ",
|
|
194
|
-
fr: "En savoir plus sur Nuxt dans la ",
|
|
195
|
-
es: "Aprenda más sobre Nuxt en la ",
|
|
194
|
+
title: t({
|
|
195
|
+
en: "Hello world",
|
|
196
|
+
fr: "Bonjour le monde",
|
|
197
|
+
es: "Hola mundo",
|
|
196
198
|
}),
|
|
197
|
-
|
|
198
|
-
en: "
|
|
199
|
-
fr: "
|
|
200
|
-
es: "
|
|
199
|
+
metaTitle: t({
|
|
200
|
+
en: "Welcome | My Application",
|
|
201
|
+
fr: "Bienvenue | Mon Application",
|
|
202
|
+
es: "Bienvenido | Mi Aplicación",
|
|
201
203
|
}),
|
|
202
|
-
|
|
203
|
-
en: "
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
204
|
+
metaDescription: t({
|
|
205
|
+
en: "Discover your multilingual Nuxt app homepage powered by Intlayer.",
|
|
206
|
+
fr: "Découvrez la page d'accueil multilingue de votre application Nuxt propulsée par Intlayer.",
|
|
207
|
+
es: "Descubre la página de inicio multilingüe de tu aplicación Nuxt impulsada por Intlayer.",
|
|
207
208
|
}),
|
|
208
209
|
},
|
|
209
210
|
} satisfies Dictionary;
|
|
210
211
|
|
|
211
|
-
export default
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
```javascript fileName="components/helloWorld.content.mjs" contentDeclarationFormat="esm"
|
|
215
|
-
import { t } from "intlayer";
|
|
216
|
-
|
|
217
|
-
/** @type {import('intlayer').Dictionary} */
|
|
218
|
-
const helloWorldContent = {
|
|
219
|
-
key: "helloworld",
|
|
220
|
-
content: {
|
|
221
|
-
count: t({
|
|
222
|
-
en: "count is ",
|
|
223
|
-
vi: "đếm là ",
|
|
224
|
-
fr: "le compte est ",
|
|
225
|
-
es: "el recuento es ",
|
|
226
|
-
}),
|
|
227
|
-
edit: t({
|
|
228
|
-
en: "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
229
|
-
vi: "Chỉnh sửa <code>components/HelloWorld.vue</code> và lưu để thử HMR",
|
|
230
|
-
fr: "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
231
|
-
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
232
|
-
}),
|
|
233
|
-
checkOut: t({
|
|
234
|
-
en: "Check out ",
|
|
235
|
-
vi: "Xem ",
|
|
236
|
-
fr: "Vérifiez ",
|
|
237
|
-
es: "Compruebe ",
|
|
238
|
-
}),
|
|
239
|
-
nuxtIntlayer: t({
|
|
240
|
-
en: "Nuxt Intlayer documentation",
|
|
241
|
-
vi: "Tài liệu Nuxt Intlayer",
|
|
242
|
-
fr: "Documentation de Nuxt Intlayer",
|
|
243
|
-
es: "Documentación de Nuxt Intlayer",
|
|
244
|
-
}),
|
|
245
|
-
learnMore: t({
|
|
246
|
-
en: "Learn more about Nuxt in the ",
|
|
247
|
-
vi: "Tìm hiểu thêm về Nuxt trong ",
|
|
248
|
-
fr: "En savoir plus sur Nuxt dans la ",
|
|
249
|
-
es: "Aprenda más sobre Nuxt en la ",
|
|
250
|
-
}),
|
|
251
|
-
nuxtDocs: t({
|
|
252
|
-
en: "Nuxt Documentation",
|
|
253
|
-
vi: "Tài liệu Nuxt",
|
|
254
|
-
fr: "Documentation Nuxt",
|
|
255
|
-
es: "Documentación de Nuxt",
|
|
256
|
-
}),
|
|
257
|
-
readTheDocs: t({
|
|
258
|
-
en: "Click on the Nuxt logo to learn more",
|
|
259
|
-
vi: "Nhấp vào logo Nuxt để tìm hiểu thêm",
|
|
260
|
-
fr: "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
261
|
-
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
262
|
-
}),
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
export default helloWorldContent;
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
```javascript fileName="components/helloWorld.content.cjs" contentDeclarationFormat="commonjs"
|
|
270
|
-
const { t } = require("intlayer");
|
|
271
|
-
|
|
272
|
-
/** @type {import('intlayer').Dictionary} */
|
|
273
|
-
// Nội dung cho HelloWorld component
|
|
274
|
-
const helloWorldContent = {
|
|
275
|
-
key: "helloworld",
|
|
276
|
-
content: {
|
|
277
|
-
count: t({ en: "count is ", vi: "số lượng là ", fr: "le compte est ", es: "el recuento es " }),
|
|
278
|
-
edit: t({
|
|
279
|
-
en: "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
280
|
-
vi: "Chỉnh sửa <code>components/HelloWorld.vue</code> và lưu để thử HMR",
|
|
281
|
-
fr: "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
282
|
-
es: "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR",
|
|
283
|
-
}),
|
|
284
|
-
checkOut: t({ en: "Check out ", vi: "Xem ", fr: "Vérifiez ", es: "Compruebe " }),
|
|
285
|
-
nuxtIntlayer: t({
|
|
286
|
-
en: "Nuxt Intlayer documentation",
|
|
287
|
-
vi: "Tài liệu Nuxt Intlayer",
|
|
288
|
-
fr: "Documentation de Nuxt Intlayer",
|
|
289
|
-
es: "Documentación de Nuxt Intlayer",
|
|
290
|
-
}),
|
|
291
|
-
es: "Documentación de Nuxt Intlayer",
|
|
292
|
-
}),
|
|
293
|
-
learnMore: t({
|
|
294
|
-
en: "Learn more about Nuxt in the ",
|
|
295
|
-
vi: "Tìm hiểu thêm về Nuxt trong ",
|
|
296
|
-
fr: "En savoir plus sur Nuxt dans la ",
|
|
297
|
-
es: "Aprenda más sobre Nuxt en la ",
|
|
298
|
-
}),
|
|
299
|
-
nuxtDocs: t({
|
|
300
|
-
en: "Nuxt Documentation",
|
|
301
|
-
vi: "Tài liệu Nuxt",
|
|
302
|
-
fr: "Documentation Nuxt",
|
|
303
|
-
es: "Documentación de Nuxt",
|
|
304
|
-
}),
|
|
305
|
-
readTheDocs: t({
|
|
306
|
-
en: "Click on the Nuxt logo to learn more",
|
|
307
|
-
vi: "Nhấp vào logo Nuxt để tìm hiểu thêm",
|
|
308
|
-
fr: "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
309
|
-
es: "Haga clic en el logotipo de Nuxt para obtener más información",
|
|
310
|
-
}),
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
module.exports = helloWorldContent;
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
```json fileName="components/helloWorld.content.json" contentDeclarationFormat="json"
|
|
318
|
-
{
|
|
319
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
320
|
-
"key": "helloworld",
|
|
321
|
-
"content": {
|
|
322
|
-
"count": {
|
|
323
|
-
"nodeType": "translation",
|
|
324
|
-
"translation": {
|
|
325
|
-
"en": "count is ",
|
|
326
|
-
"vi": "số đếm là ",
|
|
327
|
-
"fr": "le compte est ",
|
|
328
|
-
"es": "el recuento es "
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
"edit": {
|
|
332
|
-
"nodeType": "translation",
|
|
333
|
-
"translation": {
|
|
334
|
-
"en": "Edit <code>components/HelloWorld.vue</code> and save to test HMR",
|
|
335
|
-
"vi": "Chỉnh sửa <code>components/HelloWorld.vue</code> và lưu để thử HMR",
|
|
336
|
-
"fr": "Éditez <code>components/HelloWorld.vue</code> et enregistrez pour tester HMR",
|
|
337
|
-
"es": "Edita <code>components/HelloWorld.vue</code> y guarda para probar HMR"
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
"checkOut": {
|
|
341
|
-
"nodeType": "translation",
|
|
342
|
-
"translation": {
|
|
343
|
-
"en": "Check out ",
|
|
344
|
-
"vi": "Xem ",
|
|
345
|
-
"fr": "Vérifiez ",
|
|
346
|
-
"es": "Compruebe "
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
"nuxtIntlayer": {
|
|
350
|
-
"nodeType": "translation",
|
|
351
|
-
"translation": {
|
|
352
|
-
"vi": "Tài liệu Nuxt Intlayer",
|
|
353
|
-
"fr": "Documentation de Nuxt Intlayer",
|
|
354
|
-
"es": "Documentación de Nuxt Intlayer"
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
"learnMore": {
|
|
358
|
-
"nodeType": "translation",
|
|
359
|
-
"translation": {
|
|
360
|
-
"vi": "Tìm hiểu thêm về Nuxt trong ",
|
|
361
|
-
"fr": "En savoir plus sur Nuxt dans la ",
|
|
362
|
-
"es": "Aprenda más sobre Nuxt en la "
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
"nuxtDocs": {
|
|
366
|
-
"nodeType": "translation",
|
|
367
|
-
"translation": {
|
|
368
|
-
"vi": "Tài liệu Nuxt",
|
|
369
|
-
"fr": "Documentation Nuxt",
|
|
370
|
-
"es": "Documentación de Nuxt"
|
|
371
|
-
}
|
|
372
|
-
},
|
|
373
|
-
"readTheDocs": {
|
|
374
|
-
"nodeType": "translation",
|
|
375
|
-
"translation": {
|
|
376
|
-
"vi": "Nhấp vào logo Nuxt để tìm hiểu thêm",
|
|
377
|
-
"fr": "Cliquez sur le logo Nuxt pour en savoir plus",
|
|
378
|
-
"vi": "Nhấp vào logo Nuxt để tìm hiểu thêm"
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
212
|
+
export default content;
|
|
383
213
|
```
|
|
384
214
|
|
|
385
215
|
> Các khai báo nội dung của bạn có thể được định nghĩa ở bất kỳ đâu trong ứng dụng của bạn miễn là chúng được bao gồm trong thư mục `contentDir` (mặc định là `./src`). Và phù hợp với phần mở rộng tệp khai báo nội dung (mặc định là `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
@@ -437,12 +267,12 @@ const countRef = ref(0);
|
|
|
437
267
|
</template>
|
|
438
268
|
```
|
|
439
269
|
|
|
440
|
-
#### Truy cập
|
|
270
|
+
#### Truy cập nội dung trong Intlayer
|
|
441
271
|
|
|
442
272
|
Intlayer cung cấp các API khác nhau để truy cập nội dung của bạn:
|
|
443
273
|
|
|
444
|
-
- **Cú pháp dựa trên
|
|
445
|
-
Sử dụng cú pháp `<myContent />`, hoặc `<Component :is="myContent" />` để hiển thị nội dung
|
|
274
|
+
- **Cú pháp dựa trên component** (khuyến nghị):
|
|
275
|
+
Sử dụng cú pháp `<myContent />`, hoặc `<Component :is="myContent" />` để hiển thị nội dung dưới dạng một Intlayer Node. Điều này tích hợp liền mạch với [Visual Editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_visual_editor.md) và [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_CMS.md).
|
|
446
276
|
|
|
447
277
|
- **Cú pháp dựa trên chuỗi**:
|
|
448
278
|
Sử dụng `{{ myContent }}` để hiển thị nội dung dưới dạng văn bản thuần, không hỗ trợ Visual Editor.
|
|
@@ -451,72 +281,62 @@ Intlayer cung cấp các API khác nhau để truy cập nội dung của bạn:
|
|
|
451
281
|
Sử dụng `<div v-html="myContent" />` để hiển thị nội dung dưới dạng HTML thô, không hỗ trợ Visual Editor.
|
|
452
282
|
|
|
453
283
|
- **Cú pháp phân rã (Destructuration)**:
|
|
454
|
-
`useIntlayer`
|
|
455
|
-
- Sử dụng `const content = useIntlayer("myContent");` và `{{ content.myContent }}` / `<content.myContent />`.
|
|
456
|
-
- Hoặc sử dụng `const { myContent } = useIntlayer("myContent");` và `{{ myContent}}` / `<myContent/>` để
|
|
284
|
+
Composable `useIntlayer` trả về một Proxy chứa nội dung. Proxy này có thể được phân rã để truy cập nội dung trong khi vẫn giữ được tính phản ứng.
|
|
285
|
+
- Sử dụng `const content = useIntlayer("myContent");` và `{{ content.myContent }}` / `<content.myContent />`.
|
|
286
|
+
- Hoặc sử dụng `const { myContent } = useIntlayer("myContent");` và `{{ myContent}}` / `<myContent/>` để phân rã nội dung.
|
|
457
287
|
|
|
458
288
|
### (Tùy chọn) Bước 6: Thay đổi ngôn ngữ của nội dung
|
|
459
289
|
|
|
460
290
|
Để thay đổi ngôn ngữ của nội dung, bạn có thể sử dụng hàm `setLocale` được cung cấp bởi composable `useLocale`. Hàm này cho phép bạn thiết lập locale của ứng dụng và cập nhật nội dung tương ứng.
|
|
461
291
|
|
|
462
|
-
Tạo một component để chuyển đổi giữa các ngôn
|
|
292
|
+
Tạo một component để chuyển đổi giữa các ngôn ngữ sử dụng `NuxtLink`. **Sử dụng các liên kết thay vì nút bấm để chuyển đổi locale là một thực hành tốt cho SEO và khả năng khám phá trang**, vì nó cho phép các công cụ tìm kiếm thu thập dữ liệu và lập chỉ mục tất cả các phiên bản địa phương hóa của trang của bạn:
|
|
463
293
|
|
|
464
294
|
```vue fileName="components/LocaleSwitcher.vue"
|
|
465
|
-
<template>
|
|
466
|
-
<div class="locale-switcher">
|
|
467
|
-
<select v-model="selectedLocale" @change="changeLocale">
|
|
468
|
-
<option v-for="loc in availableLocales" :key="loc" :value="loc">
|
|
469
|
-
{{ getLocaleName(loc) }}
|
|
470
|
-
</option>
|
|
471
|
-
</select>
|
|
472
|
-
</div>
|
|
473
|
-
</template>
|
|
474
|
-
|
|
475
295
|
<script setup lang="ts">
|
|
476
|
-
import {
|
|
477
|
-
import { getLocaleName } from "intlayer";
|
|
296
|
+
import { getLocaleName, getLocalizedUrl } from "intlayer";
|
|
478
297
|
import { useLocale } from "vue-intlayer";
|
|
479
298
|
|
|
480
|
-
//
|
|
299
|
+
// Nuxt tự động import useRoute
|
|
300
|
+
const route = useRoute();
|
|
481
301
|
const { locale, availableLocales, setLocale } = useLocale();
|
|
482
|
-
|
|
483
|
-
// Theo dõi locale được chọn với ref
|
|
484
|
-
const selectedLocale = ref(locale.value);
|
|
485
|
-
|
|
486
|
-
// Cập nhật locale khi lựa chọn thay đổi
|
|
487
|
-
const changeLocale = () => setLocale(selectedLocale.value);
|
|
488
|
-
|
|
489
|
-
// Giữ selectedLocale đồng bộ với locale toàn cục
|
|
490
|
-
watch(
|
|
491
|
-
() => locale.value,
|
|
492
|
-
(newLocale) => {
|
|
493
|
-
selectedLocale.value = newLocale;
|
|
494
|
-
}
|
|
495
|
-
);
|
|
496
302
|
</script>
|
|
303
|
+
|
|
304
|
+
<template>
|
|
305
|
+
<nav class="locale-switcher">
|
|
306
|
+
<NuxtLink
|
|
307
|
+
v-for="localeEl in availableLocales"
|
|
308
|
+
:key="localeEl"
|
|
309
|
+
:to="getLocalizedUrl(route.fullPath, localeEl)"
|
|
310
|
+
class="locale-link"
|
|
311
|
+
:class="{ 'active-locale': localeEl === locale }"
|
|
312
|
+
@click="setLocale(localeEl)"
|
|
313
|
+
>
|
|
314
|
+
{{ getLocaleName(localeEl) }}
|
|
315
|
+
</NuxtLink>
|
|
316
|
+
</nav>
|
|
497
317
|
</template>
|
|
318
|
+
```
|
|
498
319
|
|
|
499
|
-
|
|
500
|
-
.locale-switcher {
|
|
501
|
-
margin: 1rem 0;
|
|
502
|
-
}
|
|
320
|
+
> Việc sử dụng `NuxtLink` với các thuộc tính `href` đúng cách (thông qua `getLocalizedUrl`) đảm bảo rằng các công cụ tìm kiếm có thể khám phá tất cả các biến thể ngôn ngữ của trang của bạn. Điều này ưu việt hơn so với việc chuyển đổi ngôn ngữ chỉ bằng JavaScript, mà các trình thu thập dữ liệu của công cụ tìm kiếm có thể không theo dõi được.
|
|
503
321
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
322
|
+
Sau đó, thiết lập `app.vue` của bạn để sử dụng layouts:
|
|
323
|
+
|
|
324
|
+
```vue fileName="app.vue"
|
|
325
|
+
<template>
|
|
326
|
+
<NuxtLayout>
|
|
327
|
+
<NuxtPage />
|
|
328
|
+
</NuxtLayout>
|
|
329
|
+
</template>
|
|
510
330
|
```
|
|
511
331
|
|
|
512
|
-
|
|
332
|
+
### (Tùy chọn) Bước 6b: Tạo một Layout với Điều hướng
|
|
513
333
|
|
|
514
|
-
|
|
334
|
+
Layouts của Nuxt cho phép bạn định nghĩa một cấu trúc chung cho các trang của bạn. Tạo một layout mặc định bao gồm bộ chuyển đổi ngôn ngữ và điều hướng:
|
|
335
|
+
|
|
336
|
+
```vue fileName="layouts/default.vue"
|
|
515
337
|
<script setup lang="ts">
|
|
516
|
-
import
|
|
338
|
+
import Links from "~/components/Links.vue";
|
|
517
339
|
import LocaleSwitcher from "~/components/LocaleSwitcher.vue";
|
|
518
|
-
|
|
519
|
-
const content = useIntlayer("app"); // Tạo file khai báo intlayer liên quan
|
|
520
340
|
</script>
|
|
521
341
|
|
|
522
342
|
<template>
|
|
@@ -525,15 +345,20 @@ const content = useIntlayer("app"); // Tạo file khai báo intlayer liên quan
|
|
|
525
345
|
<LocaleSwitcher />
|
|
526
346
|
</header>
|
|
527
347
|
<main>
|
|
528
|
-
<
|
|
348
|
+
<slot />
|
|
529
349
|
</main>
|
|
350
|
+
|
|
351
|
+
<Links href="/">Trang chủ</Links>
|
|
352
|
+
<Links href="/about">Giới thiệu</Links>
|
|
530
353
|
</div>
|
|
531
354
|
</template>
|
|
532
355
|
```
|
|
533
356
|
|
|
534
|
-
|
|
357
|
+
Thành phần `Links` (được hiển thị bên dưới) đảm bảo rằng các liên kết điều hướng nội bộ được tự động địa phương hóa.
|
|
535
358
|
|
|
536
|
-
|
|
359
|
+
### (Tùy chọn) Bước 7: Thêm định tuyến địa phương hóa vào ứng dụng của bạn
|
|
360
|
+
|
|
361
|
+
Nuxt tự động xử lý định tuyến địa phương hóa khi sử dụng module `nuxt-intlayer`. Điều này tạo các tuyến đường cho mỗi ngôn ngữ tự động dựa trên cấu trúc thư mục trang của bạn.
|
|
537
362
|
|
|
538
363
|
Ví dụ:
|
|
539
364
|
|
|
@@ -545,221 +370,281 @@ pages/
|
|
|
545
370
|
└── index.vue → /contact, /fr/contact, /es/contact
|
|
546
371
|
```
|
|
547
372
|
|
|
548
|
-
Để tạo
|
|
373
|
+
Để tạo các trang được địa phương hóa, chỉ cần tạo các file Vue của bạn trong thư mục `pages/`. Dưới đây là hai ví dụ về các trang:
|
|
374
|
+
|
|
375
|
+
**Trang chủ (`pages/index.vue`):**
|
|
376
|
+
|
|
377
|
+
```vue fileName="pages/index.vue"
|
|
378
|
+
<script setup lang="ts">
|
|
379
|
+
import { useIntlayer } from "vue-intlayer";
|
|
380
|
+
|
|
381
|
+
const content = useIntlayer("home-page");
|
|
382
|
+
|
|
383
|
+
useHead({
|
|
384
|
+
title: content.metaTitle.value,
|
|
385
|
+
meta: [
|
|
386
|
+
{
|
|
387
|
+
name: "description",
|
|
388
|
+
content: content.metaDescription.value,
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
});
|
|
392
|
+
</script>
|
|
393
|
+
|
|
394
|
+
<template>
|
|
395
|
+
<h1><content.title /></h1>
|
|
396
|
+
</template>
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
**Trang Giới thiệu (`pages/about.vue`):**
|
|
549
400
|
|
|
550
401
|
```vue fileName="pages/about.vue"
|
|
551
402
|
<script setup lang="ts">
|
|
552
403
|
import { useIntlayer } from "vue-intlayer";
|
|
553
404
|
|
|
554
|
-
const content = useIntlayer("about");
|
|
405
|
+
const content = useIntlayer("about-page");
|
|
406
|
+
|
|
407
|
+
useHead({
|
|
408
|
+
title: content.metaTitle.raw, // Sử dụng .raw để truy cập chuỗi nguyên thủy
|
|
409
|
+
meta: [
|
|
410
|
+
{
|
|
411
|
+
name: "description",
|
|
412
|
+
content: content.metaDescription.raw, // Sử dụng .raw để truy cập chuỗi nguyên thủy
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
});
|
|
555
416
|
</script>
|
|
556
417
|
|
|
557
418
|
<template>
|
|
558
|
-
<
|
|
559
|
-
<h1>{{ content.title }}</h1>
|
|
560
|
-
<p>{{ content.description }}</p>
|
|
561
|
-
</div>
|
|
419
|
+
<h1><content.title /></h1>
|
|
562
420
|
</template>
|
|
563
421
|
```
|
|
564
422
|
|
|
423
|
+
> Lưu ý: `useHead` được tự động import trong Nuxt. Bạn có thể truy cập giá trị nội dung bằng cách sử dụng `.value` (phản ứng) hoặc `.raw` (chuỗi nguyên thủy) tùy theo nhu cầu của bạn.
|
|
424
|
+
|
|
565
425
|
Module `nuxt-intlayer` sẽ tự động:
|
|
566
426
|
|
|
567
427
|
- Phát hiện ngôn ngữ ưu tiên của người dùng
|
|
568
428
|
- Xử lý chuyển đổi ngôn ngữ qua URL
|
|
569
|
-
-
|
|
429
|
+
- Thiết lập thuộc tính `<html lang="">` phù hợp
|
|
570
430
|
- Quản lý cookie ngôn ngữ
|
|
571
|
-
- Chuyển hướng người dùng đến URL
|
|
431
|
+
- Chuyển hướng người dùng đến URL địa phương hóa phù hợp
|
|
572
432
|
|
|
573
|
-
### (Tùy chọn) Bước 8: Tạo
|
|
433
|
+
### (Tùy chọn) Bước 8: Tạo một Component Liên kết Địa phương hóa
|
|
574
434
|
|
|
575
|
-
Để đảm bảo điều hướng trong ứng dụng của bạn
|
|
576
|
-
|
|
577
|
-
```vue fileName="components/LocalizedLink.vue"
|
|
578
|
-
<template>
|
|
579
|
-
<NuxtLink :to="localizedHref" v-bind="$attrs">
|
|
580
|
-
<slot />
|
|
581
|
-
</NuxtLink>
|
|
582
|
-
</template>
|
|
435
|
+
Để đảm bảo điều hướng trong ứng dụng của bạn tuân thủ ngôn ngữ hiện tại, bạn có thể tạo một component `Links` tùy chỉnh. Component này tự động thêm tiền tố ngôn ngữ hiện tại vào các URL nội bộ, điều này rất quan trọng cho **SEO và khả năng tìm thấy trang**.
|
|
583
436
|
|
|
437
|
+
```vue fileName="components/Links.vue"
|
|
584
438
|
<script setup lang="ts">
|
|
585
|
-
import { computed } from "vue";
|
|
586
439
|
import { getLocalizedUrl } from "intlayer";
|
|
587
440
|
import { useLocale } from "vue-intlayer";
|
|
588
441
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
442
|
+
interface Props {
|
|
443
|
+
href: string;
|
|
444
|
+
locale?: string;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const props = defineProps<Props>();
|
|
448
|
+
|
|
449
|
+
const { locale: currentLocale } = useLocale();
|
|
595
450
|
|
|
596
|
-
|
|
451
|
+
// Tính toán đường dẫn cuối cùng
|
|
452
|
+
const finalPath = computed(() => {
|
|
453
|
+
// 1. Kiểm tra xem liên kết có phải là liên kết ngoài không
|
|
454
|
+
const isExternal = /^https?:\/\//.test(props.href || "");
|
|
597
455
|
|
|
598
|
-
//
|
|
599
|
-
|
|
456
|
+
// 2. Nếu là liên kết ngoài, trả về nguyên trạng (NuxtLink xử lý việc tạo thẻ <a>)
|
|
457
|
+
if (isExternal) return props.href;
|
|
600
458
|
|
|
601
|
-
//
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
);
|
|
459
|
+
// 3. Nếu là liên kết nội bộ, địa phương hóa URL
|
|
460
|
+
const targetLocale = props.locale || currentLocale.value;
|
|
461
|
+
return getLocalizedUrl(props.href, targetLocale);
|
|
462
|
+
});
|
|
605
463
|
</script>
|
|
464
|
+
|
|
465
|
+
<template>
|
|
466
|
+
<NuxtLink :to="finalPath" v-bind="$attrs">
|
|
467
|
+
<slot />
|
|
468
|
+
</NuxtLink>
|
|
469
|
+
</template>
|
|
606
470
|
```
|
|
607
471
|
|
|
608
472
|
Sau đó sử dụng component này trong toàn bộ ứng dụng của bạn:
|
|
609
473
|
|
|
610
|
-
```vue fileName="
|
|
474
|
+
```vue fileName="layouts/default.vue"
|
|
475
|
+
<script setup lang="ts">
|
|
476
|
+
import Links from "~/components/Links.vue";
|
|
477
|
+
import LocaleSwitcher from "~/components/LocaleSwitcher.vue";
|
|
478
|
+
</script>
|
|
479
|
+
|
|
611
480
|
<template>
|
|
612
481
|
<div>
|
|
613
|
-
<
|
|
614
|
-
|
|
615
|
-
</
|
|
616
|
-
<
|
|
617
|
-
|
|
618
|
-
</
|
|
482
|
+
<header>
|
|
483
|
+
<LocaleSwitcher />
|
|
484
|
+
</header>
|
|
485
|
+
<main>
|
|
486
|
+
<slot />
|
|
487
|
+
</main>
|
|
488
|
+
|
|
489
|
+
<Links href="/">Trang chủ</Links>
|
|
490
|
+
<Links href="/about">Giới thiệu</Links>
|
|
619
491
|
</div>
|
|
620
492
|
</template>
|
|
621
|
-
|
|
622
|
-
<script setup lang="ts">
|
|
623
|
-
import { useIntlayer } from "vue-intlayer";
|
|
624
|
-
import LocalizedLink from "~/components/LocalizedLink.vue";
|
|
625
|
-
|
|
626
|
-
const content = useIntlayer("home");
|
|
627
|
-
</script>
|
|
628
493
|
```
|
|
629
494
|
|
|
495
|
+
> Bằng cách sử dụng `NuxtLink` với các đường dẫn đã được địa phương hóa, bạn đảm bảo rằng:
|
|
496
|
+
>
|
|
497
|
+
> - Các công cụ tìm kiếm có thể thu thập dữ liệu và lập chỉ mục tất cả các phiên bản ngôn ngữ của trang của bạn
|
|
498
|
+
> - Người dùng có thể chia sẻ trực tiếp các URL đã được địa phương hóa
|
|
499
|
+
> - Lịch sử trình duyệt hoạt động chính xác với các URL có tiền tố ngôn ngữ
|
|
500
|
+
|
|
630
501
|
### (Tùy chọn) Bước 9: Xử lý Metadata và SEO
|
|
631
502
|
|
|
632
|
-
Nuxt cung cấp
|
|
503
|
+
Nuxt cung cấp khả năng SEO tuyệt vời thông qua composable `useHead` (tự động import). Bạn có thể sử dụng Intlayer để xử lý metadata đã được địa phương hóa bằng cách sử dụng accessor `.raw` hoặc `.value` để lấy giá trị chuỗi nguyên thủy:
|
|
633
504
|
|
|
634
505
|
```vue fileName="pages/about.vue"
|
|
635
506
|
<script setup lang="ts">
|
|
636
|
-
import {
|
|
637
|
-
import { getIntlayer } from "intlayer";
|
|
638
|
-
import { useLocale } from "vue-intlayer";
|
|
507
|
+
import { useIntlayer } from "vue-intlayer";
|
|
639
508
|
|
|
640
|
-
|
|
641
|
-
const content =
|
|
509
|
+
// useHead được tự động import trong Nuxt
|
|
510
|
+
const content = useIntlayer("about-page");
|
|
642
511
|
|
|
643
|
-
|
|
644
|
-
title: content.
|
|
645
|
-
|
|
512
|
+
useHead({
|
|
513
|
+
title: content.metaTitle.raw, // Sử dụng .raw để truy cập giá trị chuỗi nguyên thủy
|
|
514
|
+
meta: [
|
|
515
|
+
{
|
|
516
|
+
name: "description",
|
|
517
|
+
content: content.metaDescription.raw, // Sử dụng .raw để truy cập chuỗi nguyên thủy
|
|
518
|
+
},
|
|
519
|
+
],
|
|
646
520
|
});
|
|
647
521
|
</script>
|
|
648
522
|
|
|
649
523
|
<template>
|
|
650
|
-
<
|
|
651
|
-
<h1>{{ content.pageTitle }}</h1>
|
|
652
|
-
<p>{{ content.pageContent }}</p>
|
|
653
|
-
</div>
|
|
524
|
+
<h1><content.title /></h1>
|
|
654
525
|
</template>
|
|
655
526
|
```
|
|
656
527
|
|
|
528
|
+
> Ngoài ra, bạn có thể sử dụng hàm `import { getIntlayer } from "intlayer"` để lấy nội dung mà không cần phản ứng của Vue.
|
|
529
|
+
|
|
530
|
+
> **Truy cập giá trị nội dung:**
|
|
531
|
+
>
|
|
532
|
+
> - Sử dụng `.raw` để lấy giá trị chuỗi nguyên thủy (không phản ứng)
|
|
533
|
+
> - Sử dụng `.value` để lấy giá trị phản ứng
|
|
534
|
+
> - Sử dụng cú pháp component `<content.key />` để hỗ trợ Visual Editor
|
|
535
|
+
|
|
657
536
|
Tạo khai báo nội dung tương ứng:
|
|
658
537
|
|
|
659
|
-
```ts fileName="pages/about-
|
|
538
|
+
```ts fileName="pages/about-page.content.ts" contentDeclarationFormat="typescript"
|
|
660
539
|
import { t, type Dictionary } from "intlayer";
|
|
661
|
-
import type { useSeoMeta } from "nuxt/app";
|
|
662
540
|
|
|
663
|
-
const
|
|
664
|
-
key: "about-
|
|
541
|
+
const aboutPageContent = {
|
|
542
|
+
key: "about-page",
|
|
665
543
|
content: {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
en: "About Us - My Company",
|
|
544
|
+
metaTitle: t({
|
|
545
|
+
en: "Về Chúng Tôi - Công Ty Tôi",
|
|
669
546
|
fr: "À Propos - Ma Société",
|
|
670
547
|
es: "Acerca de Nosotros - Mi Empresa",
|
|
671
548
|
}),
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
en: "Learn more about our company and our mission",
|
|
549
|
+
metaDescription: t({
|
|
550
|
+
en: "Tìm hiểu thêm về công ty và sứ mệnh của chúng tôi",
|
|
675
551
|
fr: "En savoir plus sur notre société et notre mission",
|
|
676
552
|
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
677
553
|
}),
|
|
554
|
+
title: t({
|
|
555
|
+
en: "Về Chúng Tôi",
|
|
556
|
+
fr: "À Propos",
|
|
557
|
+
es: "Acerca de Nosotros",
|
|
558
|
+
}),
|
|
678
559
|
},
|
|
679
|
-
} satisfies Dictionary
|
|
560
|
+
} satisfies Dictionary;
|
|
680
561
|
|
|
681
|
-
export default
|
|
562
|
+
export default aboutPageContent;
|
|
682
563
|
```
|
|
683
564
|
|
|
684
|
-
```
|
|
565
|
+
```javascript fileName="pages/about-page.content.mjs" contentDeclarationFormat="esm"
|
|
685
566
|
import { t } from "intlayer";
|
|
686
567
|
|
|
687
568
|
/** @type {import('intlayer').Dictionary} */
|
|
688
|
-
const
|
|
689
|
-
key: "about-
|
|
569
|
+
const aboutPageContent = {
|
|
570
|
+
key: "about-page",
|
|
690
571
|
content: {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
en: "About Us - My Company",
|
|
572
|
+
metaTitle: t({
|
|
573
|
+
en: "Về Chúng Tôi - Công Ty Tôi",
|
|
694
574
|
fr: "À Propos - Ma Société",
|
|
695
575
|
es: "Acerca de Nosotros - Mi Empresa",
|
|
696
|
-
vi: "Về Chúng Tôi - Công Ty Tôi",
|
|
697
576
|
}),
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
en: "Learn more about our company and our mission",
|
|
577
|
+
metaDescription: t({
|
|
578
|
+
en: "Tìm hiểu thêm về công ty và sứ mệnh của chúng tôi",
|
|
701
579
|
fr: "En savoir plus sur notre société et notre mission",
|
|
702
580
|
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
703
|
-
|
|
581
|
+
}),
|
|
582
|
+
title: t({
|
|
583
|
+
en: "Về Chúng Tôi",
|
|
584
|
+
fr: "À Propos",
|
|
585
|
+
es: "Acerca de Nosotros",
|
|
704
586
|
}),
|
|
705
587
|
},
|
|
706
588
|
};
|
|
707
589
|
|
|
708
|
-
export default
|
|
590
|
+
export default aboutPageContent;
|
|
709
591
|
```
|
|
710
592
|
|
|
711
|
-
```
|
|
593
|
+
```javascript fileName="pages/about-page.content.cjs" contentDeclarationFormat="commonjs"
|
|
712
594
|
const { t } = require("intlayer");
|
|
713
595
|
|
|
714
596
|
/** @type {import('intlayer').Dictionary} */
|
|
715
|
-
const
|
|
716
|
-
key: "about-
|
|
597
|
+
const aboutPageContent = {
|
|
598
|
+
key: "about-page",
|
|
717
599
|
content: {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
en: "About Us - My Company",
|
|
721
|
-
fr: "À Propos - Ma Société",
|
|
722
|
-
es: "Acerca de Nosotros - Mi Empresa",
|
|
723
|
-
vi: "Về Chúng Tôi - Công Ty Tôi",
|
|
724
|
-
}),
|
|
600
|
+
metaTitle: t({
|
|
601
|
+
en: "Về Chúng Tôi - Công Ty Tôi",
|
|
725
602
|
fr: "À Propos - Ma Société",
|
|
726
603
|
es: "Acerca de Nosotros - Mi Empresa",
|
|
727
604
|
}),
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
vi: "Tìm hiểu thêm về công ty và sứ mệnh của chúng tôi",
|
|
731
|
-
en: "Learn more about our company and our mission",
|
|
605
|
+
metaDescription: t({
|
|
606
|
+
en: "Tìm hiểu thêm về công ty và sứ mệnh của chúng tôi",
|
|
732
607
|
fr: "En savoir plus sur notre société et notre mission",
|
|
733
608
|
es: "Conozca más sobre nuestra empresa y nuestra misión",
|
|
734
609
|
}),
|
|
610
|
+
title: t({
|
|
611
|
+
en: "Về Chúng Tôi",
|
|
612
|
+
fr: "À Propos",
|
|
613
|
+
es: "Acerca de Nosotros",
|
|
614
|
+
}),
|
|
735
615
|
},
|
|
736
616
|
};
|
|
737
617
|
|
|
738
|
-
module.exports =
|
|
618
|
+
module.exports = aboutPageContent;
|
|
739
619
|
```
|
|
740
620
|
|
|
741
|
-
```json fileName="pages/about-
|
|
621
|
+
```json fileName="pages/about-page.content.json" contentDeclarationFormat="json"
|
|
742
622
|
{
|
|
743
|
-
"
|
|
623
|
+
"$schema": "https://intlayer.org/schema.json",
|
|
624
|
+
"key": "about-page",
|
|
744
625
|
"content": {
|
|
745
|
-
"
|
|
626
|
+
"metaTitle": {
|
|
746
627
|
"nodeType": "translation",
|
|
747
|
-
"
|
|
748
|
-
"
|
|
749
|
-
"vi": "Về Chúng Tôi - Công Ty Tôi",
|
|
750
|
-
"en": "About Us - My Company",
|
|
628
|
+
"translation": {
|
|
629
|
+
"en": "Về Chúng Tôi - Công Ty Tôi",
|
|
751
630
|
"fr": "À Propos - Ma Société",
|
|
752
631
|
"es": "Acerca de Nosotros - Mi Empresa"
|
|
753
632
|
}
|
|
754
633
|
},
|
|
755
|
-
"
|
|
634
|
+
"metaDescription": {
|
|
756
635
|
"nodeType": "translation",
|
|
757
|
-
"
|
|
758
|
-
"
|
|
759
|
-
"en": "Learn more about our company and our mission",
|
|
636
|
+
"translation": {
|
|
637
|
+
"en": "Tìm hiểu thêm về công ty và sứ mệnh của chúng tôi",
|
|
760
638
|
"fr": "En savoir plus sur notre société et notre mission",
|
|
761
|
-
"es": "Conozca más sobre nuestra empresa y nuestra misión"
|
|
762
|
-
|
|
639
|
+
"es": "Conozca más sobre nuestra empresa y nuestra misión"
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
"title": {
|
|
643
|
+
"nodeType": "translation",
|
|
644
|
+
"translation": {
|
|
645
|
+
"en": "Về Chúng Tôi",
|
|
646
|
+
"fr": "À Propos",
|
|
647
|
+
"es": "Acerca de Nosotros"
|
|
763
648
|
}
|
|
764
649
|
}
|
|
765
650
|
}
|
|
@@ -768,7 +653,7 @@ module.exports = aboutMetaContent;
|
|
|
768
653
|
|
|
769
654
|
### Cấu hình TypeScript
|
|
770
655
|
|
|
771
|
-
Intlayer sử dụng module augmentation để tận dụng lợi ích của TypeScript và làm cho codebase của bạn mạnh mẽ hơn.
|
|
656
|
+
Intlayer sử dụng module augmentation để tận dụng các lợi ích của TypeScript và làm cho codebase của bạn mạnh mẽ hơn.
|
|
772
657
|
|
|
773
658
|

|
|
774
659
|
|
|
@@ -788,34 +673,32 @@ Intlayer sử dụng module augmentation để tận dụng lợi ích của Typ
|
|
|
788
673
|
|
|
789
674
|
### Cấu hình Git
|
|
790
675
|
|
|
791
|
-
Khuyến nghị
|
|
676
|
+
Khuyến nghị bỏ qua các tệp được tạo bởi Intlayer. Điều này giúp bạn tránh việc commit chúng vào kho Git của mình.
|
|
792
677
|
|
|
793
|
-
Để làm điều này, bạn có thể thêm các hướng dẫn sau vào
|
|
678
|
+
Để làm điều này, bạn có thể thêm các hướng dẫn sau vào tệp `.gitignore` của bạn:
|
|
794
679
|
|
|
795
680
|
```plaintext fileName=".gitignore"
|
|
796
|
-
# Bỏ qua các
|
|
681
|
+
# Bỏ qua các tệp được tạo bởi Intlayer
|
|
797
682
|
.intlayer
|
|
798
683
|
```
|
|
799
684
|
|
|
800
685
|
### Tiện ích mở rộng VS Code
|
|
801
686
|
|
|
802
|
-
Để cải thiện trải nghiệm phát triển với Intlayer, bạn có thể cài đặt **Tiện ích mở rộng Intlayer cho VS Code** chính thức.
|
|
687
|
+
Để cải thiện trải nghiệm phát triển của bạn với Intlayer, bạn có thể cài đặt **Tiện ích mở rộng Intlayer cho VS Code** chính thức.
|
|
803
688
|
|
|
804
689
|
[Cài đặt từ VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
805
690
|
|
|
806
691
|
Tiện ích mở rộng này cung cấp:
|
|
807
692
|
|
|
808
693
|
- **Tự động hoàn thành** cho các khóa dịch.
|
|
809
|
-
- **Phát hiện lỗi thời gian thực** cho các bản dịch
|
|
694
|
+
- **Phát hiện lỗi thời gian thực** cho các bản dịch bị thiếu.
|
|
810
695
|
- **Xem trước nội dung dịch ngay trong dòng**.
|
|
811
696
|
- **Hành động nhanh** để dễ dàng tạo và cập nhật các bản dịch.
|
|
812
697
|
|
|
813
|
-
Để biết thêm chi tiết về cách sử dụng tiện ích mở rộng, hãy tham khảo [
|
|
698
|
+
Để biết thêm chi tiết về cách sử dụng tiện ích mở rộng, hãy tham khảo [tài liệu Tiện ích mở rộng Intlayer cho VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
814
699
|
|
|
815
700
|
---
|
|
816
701
|
|
|
817
|
-
###
|
|
818
|
-
|
|
819
|
-
Để tiến xa hơn, bạn có thể triển khai [trình soạn thảo trực quan](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_visual_editor.md) hoặc tách nội dung của bạn ra ngoài bằng cách sử dụng [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_CMS.md).
|
|
702
|
+
### Đi xa hơn
|
|
820
703
|
|
|
821
|
-
|
|
704
|
+
Để đi xa hơn, bạn có thể triển khai [trình chỉnh sửa trực quan](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_visual_editor.md) hoặc tách nội dung của bạn ra bên ngoài bằng cách sử dụng [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/vi/intlayer_CMS.md).
|