diff --git a/bun.lockb b/bun.lockb index 884bc3a..d3be28b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 688c146..a26b340 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "email": "kawakazu80@gmail.com" }, "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" }, diff --git a/playground/README.md b/playground/README.md new file mode 100644 index 0000000..40053f9 --- /dev/null +++ b/playground/README.md @@ -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 +``` diff --git a/playground/index.ts b/playground/index.ts new file mode 100644 index 0000000..16fee99 --- /dev/null +++ b/playground/index.ts @@ -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)