{"_id":"@adaloop/adonis-inertia-i18n","name":"@adaloop/adonis-inertia-i18n","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.2":{"name":"@adaloop/adonis-inertia-i18n","description":"Adonis i18n support for Inertia.js","version":"0.0.2","engines":{"node":">=20.6.0"},"type":"module","exports":{".":"./build/index.js","./hooks/react":"./build/src/hooks/react/index.js","./hooks/vue":"./build/src/hooks/vue/index.js"},"scripts":{"clean":"del-cli build","copy:templates":"copyfiles \"stubs/**/*.stub\" build","typecheck":"tsc --noEmit","lint":"eslint . --ext=.ts","format":"prettier --write .","quick:test":"node --import=./tsnode.esm.js --enable-source-maps bin/test.ts","pretest":"npm run lint","test":"c8 npm run quick:test","prebuild":"npm run lint && npm run clean","build":"tsc","postbuild":"npm run copy:templates","release":"np","version":"npm run build","prepublishOnly":"npm run build"},"devDependencies":{"@adonisjs/assembler":"^7.7.0","@adonisjs/core":"^6.12.0","@adonisjs/eslint-config":"^1.3.0","@adonisjs/i18n":"^2.1.1","@adonisjs/inertia":"^1.2.1","@adonisjs/prettier-config":"^1.3.0","@adonisjs/tsconfig":"^1.3.0","@inertiajs/react":"^1.2.0","@inertiajs/vue3":"^1.2.0","@japa/assert":"^3.0.0","@japa/runner":"^3.1.4","@swc/core":"^1.6.3","@types/node":"^20.14.5","c8":"^10.1.2","copyfiles":"^2.4.1","del-cli":"^5.1.0","eslint":"^8.57.0","np":"^10.0.6","prettier":"^3.3.2","ts-node":"^10.9.2","typescript":"^5.4.5","vue":"^3.5.10"},"peerDependencies":{"@inertiajs/react":"^1.2.0","@inertiajs/vue3":"^1.2.0","vue":"^3.5.10"},"author":{"name":"adaloop","email":"hello@adaloop.com"},"license":"MIT","keywords":["adonis","inertia","i18n","typescript"],"eslintConfig":{"extends":"@adonisjs/eslint-config/package"},"prettier":"@adonisjs/prettier-config","publishConfig":{"access":"public","tag":"latest"},"np":{"message":"chore(release): %s","tag":"latest","branch":"main","anyBranch":false},"c8":{"reporter":["text","html"],"exclude":["tests/**"]},"_id":"@adaloop/adonis-inertia-i18n@0.0.2","gitHead":"500d086a96c1de298f6dc14c5ee6c3fb32f71884","_nodeVersion":"21.7.3","_npmVersion":"10.8.3","dist":{"integrity":"sha512-Gyg61L9yIOthmW4NIfCNj68cZ7HIBX5YkxFj/35Y8cvh079+8fQTXhwb6njn5bTd03f4sz75baWjDua6zbh7oQ==","shasum":"c4ccb9c8e719cce1daee405561ee8646094cdda4","tarball":"https://registry.npmjs.org/@adaloop/adonis-inertia-i18n/-/adonis-inertia-i18n-0.0.2.tgz","fileCount":11,"unpackedSize":8650,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAOeVvTazeNcXwgTvi5lq2Y8II0UKDn1zuMSL1pK7f0CAiEA90wES+bvKO4vwZeaJFpCJcwB6hUXMBnMLPYT+UnXtdQ="}]},"_npmUser":{"name":"tombrulin","email":"tomm.brulin@gmail.com"},"directories":{},"maintainers":[{"name":"tombrulin","email":"tomm.brulin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/adonis-inertia-i18n_0.0.2_1727514179521_0.1255919350058683"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-28T09:02:59.423Z","0.0.2":"2024-09-28T09:02:59.720Z","modified":"2024-09-28T09:03:00.084Z"},"maintainers":[{"name":"tombrulin","email":"tomm.brulin@gmail.com"}],"description":"Adonis i18n support for Inertia.js","keywords":["adonis","inertia","i18n","typescript"],"author":{"name":"adaloop","email":"hello@adaloop.com"},"license":"MIT","readme":"# @adaloop/adonis-inertia-i18n\n\n[![GitHub Actions Status](https://img.shields.io/github/actions/workflow/status/adaloop/adonis-inertia-i18n/test.yml?branch=main&style=flat)](https://github.com/adaloop/adonis-inertia-i18n/actions?query=workflow:Tests+branch:main)\n[![Coverage Status](https://coveralls.io/repos/github/adaloop/adonis-inertia-i18n/badge.svg?branch=main)](https://coveralls.io/github/adaloop/adonis-inertia-i18n?branch=main)\n[![GitHub issues](https://img.shields.io/github/issues/adaloop/adonis-inertia-i18n)](https://img.shields.io/github/issues/adaloop/adonis-inertia-i18n)\n[![GitHub pull requests](https://img.shields.io/github/issues-pr/adaloop/adonis-inertia-i18n)](https://img.shields.io/github/issues-pr/adaloop/adonis-inertia-i18n)\n[![npm version](https://badge.fury.io/js/%40adaloop%2Fadonis-inertia-i18n.svg)](https://badge.fury.io/js/%40adaloop%2Fadonis-inertia-i18n)\n[![License](https://img.shields.io/github/license/adaloop/adonis-inertia-i18n)](https://img.shields.io/github/license/adaloop/adonis-inertia-i18n)\n\nThis package provide a simple way to use `@adonisjs/i18n` in your [AdonisJS](https://adonisjs.com) application using [InertiaJS](https://inertiajs.com).\n\n## Installation\n\nInstall and configure the package using the following command :\n\n```bash\nnode ace add @adaloop/adonis-inertia-i18n\n```\n\nThen add the following lines to your `detect_user_locale_middleware.ts` file :\n\n> [!NOTE]  \n> This file is created by `@adonisjs/i18n` package.\n\n```ts\nexport default class DetectUserLocaleMiddleware {\n  // This method already exists but you must return a string instead of string | null, then return the default locale if the user doesn't have a locale\n  protected getRequestLocale(ctx: HttpContext) {\n    const userLanguages = ctx.request.languages()\n    return i18nManager.getSupportedLocaleFor(userLanguages) ?? i18nManager.defaultLocale\n  }\n\n  async handle(ctx: HttpContext, next: NextFn) {\n    // rest of the method...\n\n    /**\n     * Sharing translations to inertia view\n     */\n    if ('inertia' in ctx) {\n      ctx.inertia.share({\n        locale: language,\n        translations: i18nManager.getTranslationsFor(language),\n      })\n    }\n\n    return next()\n  }\n}\n```\n\n## Usage\n\n### React\n\n```tsx\nimport { useI18n } from '@adaloop/adonis-inertia-i18n/hooks/react'\n\nfunction MyComponent() {\n  const { t } = useI18n()\n\n  return (\n    <>\n      <h1>{t('my.i18n.key')}</h1>\n      <p>{t('my.i18n.key', 'Fallback')}</p>\n    </>\n  )\n}\n```\n\n### Vue 3\n\n```vue\n<script setup>\nimport { useI18n } from '@adaloop/adonis-inertia-i18n/hooks/vue'\n\nconst { t } = useI18n()\n</script>\n\n<template>\n  <h1>{{ t('my.i18n.key') }}</h1>\n  <p>{{ t('my.i18n.key', 'Fallback') }}</p>\n</template>\n```\n\n## Contributing\n\nThank you for being interested in making this package better. We encourage everyone to help improve this project with new features, bug fixes, or performance improvements. Please take a little bit of your time to read our guide to make this process faster and easier.\n\n### Contribution Guidelines\n\nTo understand how to submit an issue, commit and create pull requests, check our [Contribution Guidelines](/.github/CONTRIBUTING.md).\n\n### Code of Conduct\n\nWe expect you to follow our [Code of Conduct](/.github/CODE_OF_CONDUCT.md). You can read it to understand what kind of behavior will and will not be tolerated.\n\n## License\n\n[MIT](./LICENSE.md)\n","readmeFilename":"README.md"}