@@ -8,15 +8,15 @@ Internationalization middleware & utilities for [Hono](https://hono.dev/)
88
99## 🌟 Features
1010
11+ ✅️️   ; ** Internationalization utilities:** support [ internationalization
12+ utils] ( https://github.com/intlify/srvmid/blob/main/packages/hono/docs/index.md ) via [ @intlify/utils ] ( https://github.com/intlify/utils )
13+
1114✅️   ; ** Translation:** Simple API like
1215[ vue-i18n] ( https://vue-i18n.intlify.dev/ )
1316
1417✅   ; ** Custom locale detector:** You can implement your own locale detector
1518on server-side
1619
17- ✅️️   ; ** Useful utilities:** support internationalization composables
18- utilities via [ @intlify/utils ] ( https://github.com/intlify/utils )
19-
2020## 💿 Installation
2121
2222``` sh
@@ -35,6 +35,42 @@ bun add @intlify/hono
3535
3636## 🚀 Usage
3737
38+ ### Detect locale with utils
39+
40+ Detect locale from ` accept-language ` header:
41+
42+ ``` ts
43+ import { Hono } from ' hono'
44+ import { getHeaderLocale } from ' @intlify/h3'
45+
46+ const app = new Hono ()
47+
48+ app .get (' /' , c => {
49+ // detect locale from HTTP header which has `Accept-Language: ja,en-US;q=0.7,en;q=0.3`
50+ const locale = getHeaderLocale (c .req .raw )
51+ return c .text (locale .toString ())
52+ })
53+ ```
54+
55+ Detect locale from URL query:
56+
57+ ``` ts
58+ import { Hono } from ' hono'
59+ import { getQueryLocale } from ' @intlify/h3'
60+
61+ const app = new Hono ()
62+
63+ app .get (' /' , c => {
64+ // detect locale from query which has 'http://localhost:3000?locale=en'
65+ const locale = getQueryLocale (c .req .raw )
66+ return c .text (locale .toString ())
67+ })
68+ ```
69+
70+ ### Translation
71+
72+ If you want to use translation, you need to install middleware. As a result, you can use ` useTranslation ` within the handler:
73+
3874``` ts
3975import { Hono } from ' hono'
4076import {
@@ -89,7 +125,7 @@ const DEFAULT_LOCALE = 'en'
89125// define custom locale detector
90126const localeDetector = (ctx : Context ): string => {
91127 try {
92- return getQueryLocale (ctx ).toString ()
128+ return getQueryLocale (ctx . req . raw ).toString ()
93129 } catch {
94130 return DEFAULT_LOCALE
95131 }
@@ -173,10 +209,6 @@ If you are using [Visual Studio Code](https://code.visualstudio.com/) as an edit
173209
174210< ! -- eslint-disable markdown/no-missing-label-refs -- NOTE(kazupon): ignore github alert -->
175211
176- > [! WARNING]
177- > ** This is experimental feature (inspired from [vue-i18n](https://vue-i18n.intlify.dev/guide/advanced/typescript.html#typescript-support)).**
178- > We would like to get feedback from you 🙂.
179-
180212> [! NOTE]
181213> Resource Keys completion can be used if you are using [Visual Studio Code](https://code.visualstudio.com/)
182214
0 commit comments