Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

next-intl

БесплатноБез исполняемых скриптовНе проверен

next-intl adds internationalization to Next.js App Router apps: locale-prefixed routing, ICU message translation, and locale-aware date, number and list…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

next-intl

Overview

next-intl (4.x) is an i18n library for the Next.js App Router. It provides locale routing through a proxy/middleware, JSON messages with ICU syntax (variables, plurals, dates), and hooks that work in Server and Client Components. Setup is four small files plus a [locale] route segment.

Instructions

Step 1: Install and configure the plugin

npm install next-intl
// next.config.ts
import type { NextConfig } from 'next'
import createNextIntlPlugin from 'next-intl/plugin'

const nextConfig: NextConfig = {}
const withNextIntl = createNextIntlPlugin() // finds ./src/i18n/request.ts or ./i18n/request.ts
export default withNextIntl(nextConfig)

Step 2: Routing, request config, navigation

// src/i18n/routing.ts
import { defineRouting } from 'next-intl/routing'

export const routing = defineRouting({
  locales: ['en', 'de', 'fr', 'ja'],
  defaultLocale: 'en',
  localePrefix: 'as-needed', // /about for en, /de/about for the rest; default is 'always'
})
// src/i18n/request.ts
import { hasLocale } from 'next-intl'
import { getRequestConfig } from 'next-intl/server'
import { routing } from './routing'

export default getRequestConfig(async ({ requestLocale }) => {
  const requested = await requestLocale
  const locale = hasLocale(routing.locales, requested) ? requested : routing.defaultLocale
  return {
    locale,
    messages: (await import(`../../messages/${locale}.json`)).default,
  }
})
// src/i18n/navigation.ts — locale-aware replacements for next/link and next/navigation
import { createNavigation } from 'next-intl/navigation'
import { routing } from './routing'

export const { Link, redirect, usePathname, useRouter, getPathname } = createNavigation(routing)

Step 3: Proxy (Next.js 16) or middleware (Next.js 15 and earlier)

The file is src/proxy.ts on Next.js 16 and was src/middleware.ts before. The content is the same:

import createMiddleware from 'next-intl/middleware'
import { routing } from './i18n/routing'

export default createMiddleware(routing)

export const config = {
  // skip api, trpc, _next, _vercel and anything with a dot (favicon.ico)
  matcher: '/((?!api|trpc|_next|_vercel|.*\\..*).*)',
}

Step 4: Messages and the [locale] layout

Create messages/en.json:

{
  "HomePage": {
    "title": "Welcome to {appName}",
    "teams": "Trusted by {count, plural, one {# team} other {# teams}}",
    "cta": "Get started"
  },
  "Dashboard": { "lastLogin": "Last login: {date, date, medium}" }
}

Move all pages under src/app/[locale]/. In Next.js 15+ params is a Promise:

// src/app/[locale]/layout.tsx
import { hasLocale, NextIntlClientProvider } from 'next-intl'
import { setRequestLocale } from 'next-intl/server'
import { notFound } from 'next/navigation'
import { routing } from '@/i18n/routing'

export function generateStaticParams() {
  return routing.locales.map((locale) => ({ locale }))
}

export default async function LocaleLayout({
  children,
  params,
}: {
  children: React.ReactNode
  params: Promise<{ locale: string }>
}) {
  const { locale } = await params
  if (!hasLocale(routing.locales, locale)) notFound()
  setRequestLocale(locale) // enables static rendering; also call it in each page
  return (
    <html lang={locale}>
      <body>
        <NextIntlClientProvider>{children}</NextIntlClientProvider>
      </body>
    </html>
  )
}

NextIntlClientProvider with no props passes the server's locale and messages to Client Components.

Step 5: Use translations

// src/app/[locale]/page.tsx — async Server Component
import { setRequestLocale, getTranslations } from 'next-intl/server'
import { Link } from '@/i18n/navigation'

export default async function HomePage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params
  setRequestLocale(locale)
  const t = await getTranslations('HomePage')
  return (
    <main>
      <h1>{t('title', { appName: 'Northwind' })}</h1>
      <p>{t('teams', { count: 5000 })}</p>
      <Link href="/signup">{t('cta')}</Link>
    </main>
  )
}

In a non-async component, or a Client Component marked 'use client', call useTranslations('HomePage') instead. useFormatter() / getFormatter() give format.dateTime(date, { dateStyle: 'medium' }) and format.number(1999.5, { style: 'currency', currency: 'EUR' }).

Examples

"Add German to my Next.js site." Add 'de' to locales in routing.ts, create messages/de.json with the same keys as en.json, then run npm run dev and open /de. The page renders the German strings, and <Link href="/signup"> points to /de/signup there.

"Add a language switcher." In a Client Component:

'use client'
import { useLocale } from 'next-intl'
import { usePathname, useRouter } from '@/i18n/navigation'

export function LocaleSwitcher() {
  const locale = useLocale()
  const pathname =
Полный SKILL.md на GitHub

Установить next-intl в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл next-intl?

next-intl adds internationalization to Next.js App Router apps: locale-prefixed routing, ICU message translation, and locale-aware date, number and list formatting in Server and Client Components. Use when the user asks to add multi-language support, translate a Next.js site, set up /de or /fr routes, switch language, or format dates and plurals per locale.

Как установить скилл next-intl?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл next-intl запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить next-intl с