{"_id":"@chtibizoux/hono-intlify","_rev":"1-676cb1baa44d4e07760359e6c87bc7ec","name":"@chtibizoux/hono-intlify","description":"Internationalization middleware & utilities for Hono","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.2":{"name":"@chtibizoux/hono-intlify","version":"0.1.2","keywords":["i18n","hono","honojs","internationalization","intlify","utilities","middleware"],"author":{"name":"kazuya kawaguchi","email":"kawakazu80@gmail.com"},"license":"MIT","_id":"@chtibizoux/hono-intlify@0.1.2","maintainers":[{"name":"chtibizoux","email":"5clemans585@gmail.com"}],"homepage":"https://github.com/intlify/hono#readme","bugs":{"url":"https://github.com/intlify/hono/issues"},"dist":{"shasum":"7401dd7933bf9706413115c9a3d2a592fc2a9ce4","tarball":"https://registry.npmjs.org/@chtibizoux/hono-intlify/-/hono-intlify-0.1.2.tgz","fileCount":5,"integrity":"sha512-0jXfM9Dr54vZj+ACTyZG2dtnZWHyXen2JhnvvSro74WqZBja8xSodbe+crDxW2DQ5N+X56EiAkc3xYleCVnxJA==","signatures":[{"sig":"MEYCIQCQ309ModHv21FPYGNoRwhQSCa9h4J00SQt3aJHvos1HAIhAJbnd5pS4soBq90Bmz0CZvTawKXccLwo8Eg+fKFuKfjP","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12710},"main":"dist/index.cjs","type":"module","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">= 18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./dist/*":"./dist/*","./package.json":"./package.json"},"funding":"https://github.com/sponsors/kazupon","scripts":{"fix":"npm run format && npm run lint","lint":"deno lint","test":"npm run test:type && npm run test:unit","build":"unbuild && bun run ./scripts/deno.ts","format":"deno fmt","prepare":"git config --local core.hooksPath .githooks","release":"bumpp --commit \"release: v%s\" --push --tag","changelog":"gh-changelogen --repo=intlify/hono","test:type":"vitest typecheck --run","test:unit":"vitest run","play:basic":"wrangler dev ./playground/basic/index.ts","test:coverage":"npm test -- --reporter verbose --coverage"},"_npmUser":{"name":"chtibizoux","email":"5clemans585@gmail.com"},"repository":{"url":"git+https://github.com/intlify/hono.git","type":"git"},"description":"Internationalization middleware & utilities for Hono","directories":{},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2023 kazuya kawaguchi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","lint-staged":{"*.{js,ts,jsx,tsx}":["deno lint"],"*.{js,ts,jsx,tsx,json,jsonc}":["deno fmt"]},"sideEffects":false,"dependencies":{"@intlify/core":"^9.6.0","@intlify/utils":"^0.11.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"hono":"^3.8.1","bumpp":"^9.2.0","vitest":"0.34.6","unbuild":"^2.0.0","wrangler":"^3.6.0","bun-types":"latest","miniflare":"^3.20231016.0","typescript":"^5.2.2","@types/node":"^20.6.0","lint-staged":"^15.0.0","gh-changelogen":"^0.2.8","@vitest/coverage-v8":"0.34.6","@cloudflare/workers-types":"^4.20231016.0","vitest-environment-miniflare":"^2.14.1"},"_npmOperationalInternal":{"tmp":"tmp/hono-intlify_0.1.2_1718324700518_0.18683083047134597","host":"s3://npm-registry-packages"}},"0.1.3":{"name":"@chtibizoux/hono-intlify","version":"0.1.3","description":"Internationalization middleware & utilities for Hono","keywords":["i18n","hono","honojs","internationalization","intlify","utilities","middleware"],"author":{"name":"kazuya kawaguchi","email":"kawakazu80@gmail.com"},"license":"MIT","funding":"https://github.com/sponsors/kazupon","bugs":{"url":"https://github.com/intlify/hono/issues"},"repository":{"type":"git","url":"git+https://github.com/intlify/hono.git"},"homepage":"https://github.com/intlify/hono#readme","publishConfig":{"access":"public"},"engines":{"node":">= 18"},"sideEffects":false,"type":"module","main":"dist/index.cjs","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./dist/*":"./dist/*","./package.json":"./package.json"},"scripts":{"prepare":"git config --local core.hooksPath .githooks","changelog":"gh-changelogen --repo=intlify/hono","release":"bumpp --commit \"release: v%s\" --push --tag","fix":"npm run format && npm run lint","lint":"deno lint","format":"deno fmt","build":"unbuild && bun run ./scripts/deno.ts","play:basic":"wrangler dev ./playground/basic/index.ts","test":"npm run test:type && npm run test:unit","test:type":"vitest typecheck --run","test:unit":"vitest run","test:coverage":"npm test -- --reporter verbose --coverage"},"lint-staged":{"*.{js,ts,jsx,tsx,json,jsonc}":["deno fmt"],"*.{js,ts,jsx,tsx}":["deno lint"]},"devDependencies":{"@cloudflare/workers-types":"^4.20231016.0","@types/node":"^20.6.0","@vitest/coverage-v8":"0.34.6","bumpp":"^9.2.0","bun-types":"latest","gh-changelogen":"^0.2.8","hono":"^3.8.1","miniflare":"^3.20231016.0","lint-staged":"^15.0.0","typescript":"^5.2.2","unbuild":"^2.0.0","vitest":"0.34.6","vitest-environment-miniflare":"^2.14.1","wrangler":"^3.6.0"},"dependencies":{"@intlify/core":"^9.6.0","@intlify/utils":"^0.11.1"},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2023 kazuya kawaguchi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"@chtibizoux/hono-intlify@0.1.3","dist":{"shasum":"8a3c3ba5131a0c8e68c38cdf9b778deadf92aa7f","integrity":"sha512-yBkOouYT8vN4FAVSGSnI4FioNzaalacI2LghRAdWkQ3LMJK1Zyjkhp/UgfrHj31uKlfNDdDMb0ZnysMSy0GqUA==","tarball":"https://registry.npmjs.org/@chtibizoux/hono-intlify/-/hono-intlify-0.1.3.tgz","fileCount":11,"unpackedSize":46520,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDtaTCcB6nt+/zthYXnzE2ixaei1dU5QDp9ZV+yupV+lwIgF1JJH4JFEKpgsTxtWbmif7D1Qh91v1kv5Nzk4VGKKjI="}]},"_npmUser":{"name":"chtibizoux","email":"5clemans585@gmail.com"},"directories":{},"maintainers":[{"name":"chtibizoux","email":"5clemans585@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hono-intlify_0.1.3_1718325417752_0.4662577888041115"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-14T00:25:00.427Z","modified":"2024-06-14T00:36:58.174Z","0.1.2":"2024-06-14T00:25:00.662Z","0.1.3":"2024-06-14T00:36:57.989Z"},"maintainers":[{"name":"chtibizoux","email":"5clemans585@gmail.com"}],"author":{"name":"kazuya kawaguchi","email":"kawakazu80@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/intlify/hono.git"},"keywords":["i18n","hono","honojs","internationalization","intlify","utilities","middleware"],"license":"MIT","homepage":"https://github.com/intlify/hono#readme","bugs":{"url":"https://github.com/intlify/hono/issues"},"readme":"# @intlify/hono\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![CI][ci-src]][ci-href]\n\nInternationalization middleware & utilities for [Hono](https://hono.dev/)\n\n## 🌟 Features\n\n✅️ &nbsp;**Translation:** Simple API like\n[vue-i18n](https://vue-i18n.intlify.dev/)\n\n✅ &nbsp;**Custom locale detector:** You can implement your own locale detector\non server-side\n\n✅️️ &nbsp;**Useful utilities:** support internationalization composables\nutilities via [@intlify/utils](https://github.com/intlify/utils)\n\n## 💿 Installation\n\n```sh\n# Using npm\nnpm install @intlify/hono\n\n# Using yarn\nyarn add @intlify/hono\n\n# Using pnpm\npnpm add @intlify/hono\n\n# Using bun\nbun add @intlify/hono\n```\n\n## 🚀 Usage\n\n```ts\nimport { Hono } from 'hono'\nimport {\n  defineI18nMiddleware,\n  detectLocaleFromAcceptLanguageHeader,\n  useTranslation,\n} from '@intlify/hono'\n\n// define middleware with vue-i18n like options\nconst i18nMiddleware = defineI18nMiddleware({\n  // detect locale with `accept-language` header\n  locale: detectLocaleFromAcceptLanguageHeader,\n  // resource messages\n  messages: {\n    en: {\n      hello: 'Hello {name}!',\n    },\n    ja: {\n      hello: 'こんにちは、{name}！',\n    },\n  },\n  // something options\n  // ...\n})\n\nconst app = new Hono()\n\n// install middleware with `app.use`\napp.use('*', i18nMiddleware)\n\napp.get('/', c => {\n  // use `useTranslation` in handler\n  const t = useTranslation(c)\n  return c.text(t('hello', { name: 'hono' }) + `\\n`)\n})\n\nexport default app\n```\n\n## 🛠️ Custom locale detection\n\nYou can detect locale with your custom logic from current `Context`.\n\nexample for detecting locale from url query:\n\n```ts\nimport { defineI18nMiddleware, getQueryLocale } from '@intlify/hono'\nimport type { Context } from 'hono'\n\nconst DEFAULT_LOCALE = 'en'\n\n// define custom locale detector\nconst localeDetector = (ctx: Context): string => {\n  try {\n    return getQueryLocale(ctx).toString()\n  } catch () {\n    return DEFAULT_LOCALE\n  }\n}\n\nconst middleware = defineI18nMiddleware({\n  // set your custom locale detector\n  locale: localeDetector,\n  // something options\n  // ...\n})\n```\n\n## 🧩 Type-safe resources\n\n> [!WARNING]  \n> **This is experimental feature (inspired from [vue-i18n](https://vue-i18n.intlify.dev/guide/advanced/typescript.html#typescript-support)).**\n> We would like to get feedback from you 🙂.\n\n> [!NOTE]\n> The exeample code is [here](https://github.com/intlify/hono/tree/main/playground/typesafe-schema)\n\nYou can support the type-safe resources with schema using TypeScript on `defineI18nMiddleware` options.\n\nLocale messages resource:\n\n```ts\nexport default {\n  hello: 'hello, {name}!'\n}\n```\n\nyour application code:\n\n```ts\nimport { defineI18nMiddleware } from '@intlify/hono'\nimport en from './locales/en.ts'\n\n// define resource schema, as 'en' is master resource schema\ntype ResourceSchema = typeof en\n\nconst i18nMiddleware = defineI18nMiddleware<[ResourceSchema], 'en' | 'ja'>({\n  messages: {\n    en: { hello: 'Hello, {name}' },\n  },\n  // something options\n  // ...\n})\n\n// someting your implementation code ...\n// ...\n```\n\nResult of type checking with `tsc`:\n\n```sh\nnpx tsc --noEmit\nindex.ts:13:3 - error TS2741: Property 'ja' is missing in type '{ en: { hello: string; }; }' but required in type '{ en: ResourceSchema; ja: ResourceSchema; }'.\n\n13   messages: {\n     ~~~~~~~~\n\n  ../../node_modules/@intlify/core/node_modules/@intlify/core-base/dist/core-base.d.ts:125:5\n    125     messages?: {\n            ~~~~~~~~\n    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<...>>'\n\n\nFound 1 error in index.ts:13\n```\n\nIf 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.\n\n![Type-safe resources](assets/typesafe-schema.png)\n\n\n## 🖌️ Resource keys completion\n\n> [!WARNING]  \n> **This is experimental feature (inspired from [vue-i18n](https://vue-i18n.intlify.dev/guide/advanced/typescript.html#typescript-support)).**\n> We would like to get feedback from you 🙂.\n\n> [!NOTE]\n> Resource Keys completion can be used if you are using [Visual Studio Code](https://code.visualstudio.com/)\n\nYou can completion resources key on translation function with `useTranslation`.\n\n![Key Completion](assets/key-completion.gif)\n\nresource keys completion has twe ways.\n\n### Type parameter for `useTranslation`\n\n> [!NOTE]\n> The exeample code is [here](https://github.com/intlify/hono/tree/main/playground/local-schema)\n\nYou can `useTranslation` set the type parameter to the resource schema you want to key completion of the translation function.\n\nthe part of example:\n```ts\napp.get('/', c => {\n  type ResourceSchema = {\n    hello: string\n  }\n  // set resource schema as type parameter\n  const t = useTranslation<ResourceSchema>(c)\n  // you can completion when you type `t('`\n  return c.json(t('hello', { name: 'hono' }))\n}),\n```\n\n### global resource schema with `declare module '@intlify/hono'`\n\n> [!NOTE]\n> The exeample code is [here](https://github.com/intlify/hono/tree/main/playground/global-schema)\n\nYou can do resource key completion with the translation function using the typescript `declare module`.\n\nthe part of example:\n```ts\nimport en from './locales/en.ts'\n\n// 'en' resource is master schema\ntype ResourceSchema = typeof en\n\n// you can put the type extending with `declare module` as global resource schema\ndeclare module '@intlify/hono' {\n  // extend `DefineLocaleMessage` with `ResourceSchema`\n  export interface DefineLocaleMessage extends ResourceSchema {}\n}\n\napp.get('/', c => {\n  const t = useTranslation(c)\n  // you can completion when you type `t('`\n  return c.json(t('hello', { name: 'hono' }))\n}),\n\n```\n\nThe advantage of this way is that it is not necessary to specify the resource schema in the `useTranslation` type parameter.\n\n\n## 🛠️ Utilites & Helpers\n\n`@intlify/hono` has a concept of composable utilities & helpers.\n\n### Utilities\n\n`@intlify/hono` composable utilities accept context (from\n`(context) => {})`) as their first argument. (Exclud `useTranslation`) return the [`Intl.Locale`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)\n\n### Translations\n\n- `useTranslation(context)`: use translation function\n\n### Headers\n\n- `getHeaderLocale(context, options)`: get locale from `accept-language` header\n- `getHeaderLocales(context, options)`: get some locales from `accept-language` header\n\n### Cookies\n\n- `getCookieLocale(context, options)`: get locale from cookie\n- `setCookieLocale(context, options)`: set locale to cookie\n\n### Misc\n\n- `getPathLocale(context, options)`: get locale from path\n- `getQueryLocale(context, options)`: get locale from query\n\n## Helpers\n\n- `detectLocaleFromAcceptLanguageHeader(context)`: detect locale from `accept-language` header\n\n## 🙌 Contributing guidelines\n\nIf you are interested in contributing to `@intlify/hono`, I highly recommend checking out [the contributing guidelines](/CONTRIBUTING.md) here. You'll find all the relevant information such as [how to make a PR](/CONTRIBUTING.md#pull-request-guidelines), [how to setup development](/CONTRIBUTING.md#development-setup)) etc., there.\n\n## ©️ License\n\n[MIT](http://opensource.org/licenses/MIT)\n\n<!-- Badges -->\n\n[npm-version-src]: https://img.shields.io/npm/v/@intlify/hono?style=flat&colorA=18181B&colorB=FFAD33\n[npm-version-href]: https://npmjs.com/package/@intlify/hono\n[npm-downloads-src]: https://img.shields.io/npm/dm/@intlify/hono?style=flat&colorA=18181B&colorB=FFAD33\n[npm-downloads-href]: https://npmjs.com/package/@intlify/hono\n[ci-src]: https://github.com/intlify/utils/actions/workflows/ci.yml/badge.svg\n[ci-href]: https://github.com/intlify/utils/actions/workflows/ci.yml\n","readmeFilename":"README.md"}