Skip to content

Use translator after onAfterResponse #80

@makkalay

Description

@makkalay

Describe the bug

That line of code cause problems -

h3/src/index.ts

Line 142 in 19a13c6

delete event.context.i18n

Translation error: undefined is not an object (evaluating 'event.context.i18n.locale = locale')                

    at useTranslation (node_modules/@intlify/h3/dist/index.mjs:41:19)
    at processTicksAndRejections (native:7:39)



Translation error: middleware not initialized, please setup onRequest and onAfterResponse options of createApp with the middleware obtained with defineI18nMiddleware

    at useTranslation (node_modules/@intlify/h3/dist/index.mjs:33:15)
    at useTranslation (node_modules/@intlify/h3/dist/index.mjs:31:31)
    at t (.nuxt/dev/index.mjs:5628:33)
    at t (.nuxt/dev/index.mjs:5625:11)
    at <anonymous> (.nuxt/dev/index.mjs:18522:68)
    at processTicksAndRejections (native:7:39)

Who say what i will not need to translate something after onAfterResponse?
I have code that run after, and it should run after.

Reproduction

h3/src/index.ts

Line 142 in 19a13c6

delete event.context.i18n

System Info

latest linux, node, nuxt

Used Package Manager

n/a

Additional context

onAfterResponse(event) {
      i18n.locale = orgLocale;
      // delete event.context.i18n;
 }
```

solve the problem

### Validations

- [x] Follow our [Code of Conduct](https://github.com/intlify/.github/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [Contributing Guide](https://github.com/intlify/h3/blob/main/CONTRIBUTING.md).
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [x] The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions