npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@intlify/nitro

v2.1.2

Published

Internationalization for Nitro

Readme

npm version npm downloads CI

Internationalization for Nitro

🌟 Features

✅️️  Internationalization utils: support internationalization utils via @intlify/utils

✅️  Translation: Simple API like vue-i18n

✅  Custom locale detector: You can implement your own locale detector on server-side

✅  Nitro plugin: Optimized for Nitro v3 plugin system

💿 Installation

# Using npm
npm install @intlify/nitro

# Using yarn
yarn add @intlify/nitro

# Using pnpm
pnpm add @intlify/nitro

# Using bun
bun add @intlify/nitro

🚀 Usage

Plugin setup

Create a Nitro plugin to enable internationalization:

// server/plugins/i18n.ts
import { intlify, detectLocaleFromAcceptLanguageHeader } from '@intlify/nitro'

export default intlify({
  // detect locale with `accept-language` header
  locale: detectLocaleFromAcceptLanguageHeader,
  // resource messages
  messages: {
    en: {
      hello: 'Hello {name}!'
    },
    ja: {
      hello: 'こんにちは、{name}!'
    }
  }
})

Translation

Use useTranslation in your route handlers:

// server/routes/index.ts
import { defineHandler } from 'nitro'
import { useTranslation } from '@intlify/nitro'

export default defineHandler(async event => {
  const t = await useTranslation(event)
  return t('hello', { name: 'Nitro' })
})

Detect locale with utils

Detect locale from accept-language header:

// server/routes/locale.ts
import { defineHandler } from 'nitro'
import { getHeaderLocale } from '@intlify/nitro'

export default defineHandler(event => {
  const locale = getHeaderLocale(event.req)
  return locale.toString()
})

🛠️ Custom locale detection

You can detect locale with your custom logic from the current HTTP event.

Example for detecting locale from URL query:

// server/plugins/i18n.ts
import { intlify, getQueryLocale } from '@intlify/nitro'

import type { HTTPEvent } from 'nitro/h3'

const localeDetector = (event: HTTPEvent): string => {
  return getQueryLocale(event.req).toString()
}

export default intlify({
  locale: localeDetector,
  messages: {
    en: { hello: 'Hello {name}!' },
    ja: { hello: 'こんにちは、{name}!' }
  }
})

You can also get the detected locale in route handlers with getDetectorLocale:

// server/routes/index.ts
import { defineHandler } from 'nitro'
import { getDetectorLocale } from '@intlify/nitro'

export default defineHandler(async event => {
  const locale = await getDetectorLocale(event)
  return `Current Locale: ${locale.language}`
})

You can make that function asynchronous. This is useful when loading resources along with locale detection.

[!NOTE] The case which a synchronous function returns a promise is not supported. you need to use async function.

// server/plugins/i18n.ts
import { intlify, getCookieLocale } from '@intlify/nitro'

import type { HTTPEvent } from 'nitro/h3'
import type { DefineLocaleMessage, CoreContext } from '@intlify/nitro'

const loader = (path: string) => import(path).then(m => m.default)
const messages: Record<string, () => ReturnType<typeof loader>> = {
  en: () => loader('./locales/en.json'),
  ja: () => loader('./locales/ja.json')
}

const localeDetector = async (
  event: HTTPEvent,
  intlify: CoreContext<string, DefineLocaleMessage>
): Promise<string> => {
  const locale = getCookieLocale(event.req).toString()

  const loader = messages[locale]
  if (loader && !intlify.messages[locale]) {
    const message = await loader()
    intlify.messages[locale] = message
  }

  return locale
}

export default intlify({
  locale: localeDetector
})

🖌️ Resource keys completion

[!NOTE] Resource Keys completion can be used if you are using Visual Studio Code

You can completion resources key on translation function with useTranslation.

Type parameter for useTranslation

You can set the type parameter to the resource schema for key completion of the translation function:

// server/routes/index.ts
import { defineHandler } from 'nitro'
import { useTranslation } from '@intlify/nitro'

export default defineHandler(async event => {
  type ResourceSchema = {
    hello: string
  }
  const t = await useTranslation<ResourceSchema>(event)
  return t('hello', { name: 'Nitro' })
})

Global resource schema with declare module '@intlify/nitro'

You can do resource key completion with the translation function using the typescript declare module:

import en from './locales/en.ts'

type ResourceSchema = typeof en

declare module '@intlify/nitro' {
  export interface DefineLocaleMessage extends ResourceSchema {}
}

The advantage of this way is that it is not necessary to specify the resource schema in the useTranslation type parameter.

🛠️ Utilities & Helpers

@intlify/nitro has a concept of composable utilities & helpers.

See the API References

🙌 Contributing guidelines

If you are interested in contributing to @intlify/nitro, I highly recommend checking out the contributing guidelines here. You'll find all the relevant information such as how to make a PR, how to setup development) etc., there.

🤝 Sponsors

The development of srvmid is supported by my OSS sponsors!

©️ License

MIT