-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"funding": "https://github.com/sponsors/kazupon", | ||
"bugs": { | ||
"url": "https://github.com/intlify/h3/issues" | ||
}, | ||
|
@@ -32,6 +33,7 @@ | |
"engines": { | ||
"node": ">= 18" | ||
}, | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
|
@@ -47,12 +49,12 @@ | |
}, | ||
"scripts": { | ||
"prepare": "git config --local core.hooksPath .githooks", | ||
"preinstall": "node scripts/preinstall.js", | ||
"changelog": "gh-changelogen --repo=intlify/h3", | ||
"release": "bumpp --commit \"release: v%s\" --push --tag", | ||
"lint": "deno lint", | ||
"format": "deno fmt", | ||
"build": "unbuild", | ||
"play": "bun run ./playground/index.ts", | ||
"test": "vitest run", | ||
"test:coverage": "npm test -- --reporter verbose --coverage" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `@intlify/h3` playground | ||
|
||
This playground is translation with `accept-language` header. | ||
|
||
## Usage | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
and then, you try to access to `http://localhost:3000` with `accept-language` | ||
header with another shell: | ||
|
||
```sh | ||
curl -H 'Accept-Language: ja,en-US;q=0.7,en;q=0.3' http://localhost:3000 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createServer } from 'node:http' | ||
import { createApp, createRouter, eventHandler, toNodeListener } from 'h3' | ||
import { | ||
defineI18nMiddleware, | ||
detectLocaleFromAcceptLanguageHeader, | ||
useTranslation, | ||
} from '../src/index' | ||
|
||
const middleware = defineI18nMiddleware({ | ||
locale: detectLocaleFromAcceptLanguageHeader, | ||
messages: { | ||
en: { | ||
hello: 'hello, {name}', | ||
}, | ||
ja: { | ||
hello: 'こんにちは, {name}', | ||
}, | ||
}, | ||
}) | ||
|
||
const app = createApp({ ...middleware }) | ||
|
||
const router = createRouter() | ||
router.get( | ||
'/', | ||
eventHandler((event) => { | ||
const t = useTranslation(event) | ||
return t('hello', { name: 'h3' }) | ||
}), | ||
) | ||
|
||
app.use(router) | ||
createServer(toNodeListener(app)).listen(3000) |