@@ -76,18 +76,18 @@ app.get('/', event => {
7676
7777### Translation
7878
79- If you want to use translation, you need to install plugin. As a result, you can use ` useTranslation ` within the handler:
79+ If you want to use translation, you need to install ` intlify ` plugin. As a result, you can use ` useTranslation ` within the handler:
8080
8181``` ts
8282import { createServer } from ' node:http'
8383import { H3 , toNodeListener } from ' h3'
84- import { plugin as i18n , detectLocaleFromAcceptLanguageHeader , useTranslation } from ' @intlify/h3'
84+ import { intlify , detectLocaleFromAcceptLanguageHeader , useTranslation } from ' @intlify/h3'
8585
86- // install plugin with `H3` constructor
86+ // install `intlify` plugin with `H3` constructor
8787const app = new H3 ({
8888 plugins: [
8989 // configure plugin options
90- i18n ({
90+ intlify ({
9191 // detect locale with `accept-language` header
9292 locale: detectLocaleFromAcceptLanguageHeader ,
9393 // resource messages
@@ -150,7 +150,7 @@ example for detecting locale from url query:
150150
151151``` ts
152152import { H3 } from ' h3'
153- import { plugin as i18n , getQueryLocale } from ' @intlify/h3'
153+ import { intlify , getQueryLocale } from ' @intlify/h3'
154154
155155import type { H3Event } from ' h3'
156156
@@ -161,7 +161,7 @@ const localeDetector = (event: H3Event): string => {
161161
162162const app = new H3 ({
163163 plugins: [
164- i18n ({
164+ intlify ({
165165 // set your custom locale detector
166166 locale: localeDetector
167167 // something options
@@ -182,7 +182,7 @@ You can make that function asynchronous. This is useful when loading resources a
182182
183183``` ts
184184import { H3 } from ' h3'
185- import { plugin as i18n , getCookieLocale } from ' @intlify/h3'
185+ import { intlify , getCookieLocale } from ' @intlify/h3'
186186
187187import type { H3Event } from ' h3'
188188import type { DefineLocaleMessage , CoreContext } from ' @intlify/h3'
@@ -213,7 +213,7 @@ const localeDetector = async (
213213
214214const app = new H3 ({
215215 plugins: [
216- i18n ({
216+ intlify ({
217217 // set your custom locale detector
218218 locale: localeDetector
219219 // something options
@@ -223,77 +223,6 @@ const app = new H3({
223223})
224224```
225225
226- ## 🧩 Type-safe resources
227-
228- <!-- eslint-disable markdown/no-missing-label-refs -- NOTE(kazupon): ignore github alert -->
229-
230- > [ !WARNING]
231- > ** This is experimental feature (inspired from [ vue-i18n] ( https://vue-i18n.intlify.dev/guide/advanced/typescript.html#typescript-support ) ).**
232- > We would like to get feedback from you 🙂.
233-
234- > [ !NOTE]
235- > The example code is [ here] ( https://github.com/intlify/h3/tree/main/playground/typesafe-schema )
236-
237- <!-- eslint-enable markdown/no-missing-label-refs -- NOTE(kazupon): ignore github alert -->
238-
239- You can support the type-safe resources with schema using TypeScript on ` defineI18nMiddleware ` options.
240-
241- Locale messages resource:
242-
243- ``` ts
244- export default {
245- hello: ' hello, {name}!'
246- }
247- ```
248-
249- your application code:
250-
251- ``` ts
252- import { defineI18nMiddleware } from ' @intlify/h3'
253- import { H3 } from ' h3'
254- import en from ' ./locales/en.ts'
255-
256- // define resource schema, as 'en' is master resource schema
257- type ResourceSchema = typeof en
258-
259- const i18nMiddleware = defineI18nMiddleware <[ResourceSchema ], ' en' | ' ja' >({
260- messages: {
261- en: { hello: ' Hello, {name}' }
262- }
263- // something options
264- // ...
265- })
266-
267- const app = new H3 ()
268- app .use (i18nMiddleware .onRequest )
269- app .use (i18nMiddleware .onResponse )
270-
271- // something your implementation code ...
272- // ...
273- ```
274-
275- Result of type checking with ` tsc ` :
276-
277- ``` sh
278- npx tsc --noEmit
279- index.ts:13:3 - error TS2741: Property ' ja' is missing in type ' { en: { hello: string; }; }' but required in type ' { en: ResourceSchema; ja: ResourceSchema; }' .
280-
281- 13 messages: {
282- ~ ~~~~~~~
283-
284- ../../node_modules/@intlify/core/node_modules/@intlify/core-base/dist/core-base.d.ts:125:5
285- 125 messages? : {
286- ~ ~~~~~~~
287- The expected type comes from property ' messages' which is declared here on type ' CoreOptions<string, { message: ResourceSchema; datetime: DateTimeFormat; number: NumberFormat; }, { messages: "en"; datetimeFormats: "en"; numberFormats: "en"; } | { ...; }, ... 8 more ..., NumberFormats<...>>'
288-
289-
290- Found 1 error in index.ts:13
291- ` ` `
292-
293- If you are using [Visual Studio Code](https://code.visualstudio.com/) as an editor, you can notice that there is a resource definition omission in the editor with the following error before you run the typescript compilation.
294-
295- ! [Type-safe resources](assets/typesafe-schema.png)
296-
297226## 🖌️ Resource keys completion
298227
299228<!-- eslint-disable markdown/no-missing-label-refs -- NOTE(kazupon): ignore github alert -->
0 commit comments