vitakili

localized slugs

by vitakili
payload-plugins
Redirects & URLs
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds a computed localizedSlugs field to configured collections, collecting slug and fullPath values for each locale. It is configured per collection through the plugins array and works with localized slug fields, with optional slug generation from a title and custom diacritics mapping. It also ships client components for Next.js, including a provider and a hook for language switchers. Built for Payload v3.

Features

  • Builds a localizedSlugs field holding slug and fullPath for each locale
  • Per-collection settings for slug field, full path field and title field
  • Optional slug generation from a localized title with diacritics removal
  • Custom diacritics map and configurable locales
  • Full path support for hierarchical collections with a parent
  • Client provider, handler component and hook for Next.js language switchers

Use cases

  • Build language switchers that link to the translated URL of the current page
  • Keep per-locale URL slugs and full paths in sync on multilingual page collections
  • Generate clean ASCII slugs from Czech or other accented titles

From the author

Localized slugs plugin for Payload CMS v3 with multi-locale support

Installation

npm i @kilivi/payloadcms-localized-slugs

9

Stars

1

Forks

0

Open Issues

3 weeks ago

Last Updated

83

Weekly Downloads

v1.1.9

npm Version

110.2 KB

Unpacked Size

0

Dependencies

Repository stars

90 since Sep 6

Show data
Repository stars by day (UTC)
DateStars
Dec 5, 20269
Dec 4, 20269
Dec 3, 20269
Dec 2, 20269
Dec 1, 20269
Nov 30, 20269
Nov 29, 20269
Nov 28, 20269
Nov 27, 20269
Nov 26, 20269
Nov 25, 20269
Nov 24, 20269
Nov 23, 20269
Nov 22, 20269
Nov 21, 20269
Nov 20, 20269
Nov 19, 20269
Nov 18, 20269
Nov 17, 20269
Nov 16, 20269
Nov 15, 20269
Nov 14, 20269
Nov 13, 20269
Nov 12, 20269
Nov 11, 20269
Nov 10, 20269
Nov 9, 20269
Nov 8, 20269
Nov 7, 20269
Nov 6, 20269
Nov 5, 20269
Nov 4, 20269
Nov 3, 20269
Nov 2, 20269
Nov 1, 20269
Oct 31, 20269
Oct 30, 20269
Oct 29, 20269
Oct 28, 20269
Oct 27, 20269
Oct 26, 20269
Oct 25, 20269
Oct 24, 20269
Oct 23, 20269
Oct 22, 20269
Oct 21, 20269
Oct 20, 20269
Oct 19, 20269
Oct 18, 20269
Oct 17, 20269
Oct 16, 20269
Oct 15, 20269
Oct 14, 20269
Oct 13, 20269
Oct 12, 20269
Oct 11, 20269
Oct 10, 20269
Oct 9, 20269
Oct 8, 20269
Oct 7, 20269
Oct 6, 20269
Oct 5, 20269
Oct 4, 20269
Oct 3, 20269
Oct 2, 20269
Oct 1, 20269
Sep 30, 20269
Sep 29, 20269
Sep 28, 20269
Sep 27, 20269
Sep 26, 20269
Sep 25, 20269
Sep 24, 20269
Sep 23, 20269
Sep 22, 20269
Sep 21, 20269
Sep 20, 20269
Sep 19, 20269
Sep 18, 20269
Sep 17, 20269
Sep 16, 20269
Sep 15, 20269
Sep 14, 20269
Sep 13, 20269
Sep 12, 20269
Sep 11, 20269
Sep 10, 20269
Sep 9, 20269
Sep 8, 20269
Sep 7, 20269
Sep 6, 20269

Shared by 3 plugins in vitakili/payload-plugins.

npm weekly downloads

76−4 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202676
Dec 4, 202681
Dec 3, 2026141
Dec 2, 2026135
Dec 1, 202684
Nov 30, 202686
Nov 29, 202696
Nov 28, 202693
Nov 27, 2026102
Nov 26, 202657
Nov 25, 202672
Nov 24, 2026132
Nov 23, 2026323
Nov 22, 2026318
Nov 21, 2026332
Nov 20, 2026320
Nov 19, 2026306
Nov 18, 2026292
Nov 17, 2026228
Nov 16, 202640
Nov 15, 202633
Nov 14, 202624
Nov 13, 202621
Nov 12, 202621
Nov 11, 202672
Nov 10, 2026126
Nov 9, 2026122
Nov 8, 2026121
Nov 7, 2026124
Nov 6, 2026125
Nov 5, 2026128
Nov 4, 202677
Nov 3, 202633
Nov 2, 202636
Nov 1, 202638
Oct 31, 202627
Oct 30, 202625
Oct 29, 202620
Oct 28, 202618
Oct 27, 202614
Oct 26, 202613
Oct 25, 202612
Oct 24, 202614
Oct 23, 202614
Oct 22, 202617
Oct 21, 202628
Oct 20, 202625
Oct 19, 202623
Oct 18, 202623
Oct 17, 202624
Oct 16, 202625
Oct 15, 202623
Oct 14, 202666
Oct 13, 202666
Oct 12, 202665
Oct 11, 202666
Oct 10, 202661
Oct 9, 202668
Oct 8, 202668
Oct 7, 202615
Oct 6, 202617
Oct 5, 202618
Oct 4, 202620
Oct 3, 202628
Oct 2, 202629
Oct 1, 202633
Sep 30, 202636
Sep 29, 202634
Sep 28, 202642
Sep 27, 202640
Sep 26, 202640
Sep 25, 202636
Sep 24, 202641
Sep 23, 202644
Sep 22, 202649
Sep 21, 202693
Sep 20, 202698
Sep 19, 202693
Sep 18, 2026102
Sep 17, 2026300
Sep 16, 2026299
Sep 15, 2026294
Sep 14, 2026242
Sep 13, 2026235
Sep 12, 2026246
Sep 11, 2026285
Sep 10, 202679
Sep 9, 202676
Sep 8, 202677
Sep 7, 202679
Sep 6, 202680

Each point is npm's rolling 7-day download count.

Health Score

78/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1070225561-localized-slugs.svg)](https://payloaddirectory.dev/plugins/1070225561-localized-slugs)
HTML
<a href="https://payloaddirectory.dev/plugins/1070225561-localized-slugs"><img src="https://payloaddirectory.dev/badge/1070225561-localized-slugs.svg" alt="Payload Directory"></a>
Updated Nov 14, 2026Created Oct 5, 2025Published Nov 14, 2026

README

@kilivi/payloadcms-localized-slugs

Localized slugs plugin for Payload CMS v3 with multi-locale support. Automatically copies and manages URL-friendly slugs for collections with internationalization (i18n) capabilities.

Features

  • 🌐 Multi-locale slug support (Czech, English, and extensible)
  • � Copy slug/fullPath values from existing localized fields to localizedSlugs
  • 🎯 Automatic localization detection (handles both localized and non-localized fields)
  • 🔗 Full path support for hierarchical content
  • ⚙️ Configurable per-collection settings
  • 📦 Zero dependencies (Payload only)
  • ✅ TypeScript support with full type safety
  • 🎨 Client-side components for frontend integration
  • ✅ Fully compatible with multitenant plugins - no infinite loops!

Documentation

Installation

npm install @kilivi/payloadcms-localized-slugs
# or
pnpm add @kilivi/payloadcms-localized-slugs
# or
yarn add @kilivi/payloadcms-localized-slugs

Basic Usage

import { localizedSlugsPlugin } from '@kilivi/payloadcms-localized-slugs'

export default buildConfig({
  plugins: [
    localizedSlugsPlugin({
      enabled: true,
      locales: ['cs', 'en'],
      collections: [
        {
          collection: 'pages',
          slugField: 'slug',
          fullPathField: 'fullPath',
        },
      ],
      enableLogging: true, // Show debug logs
    }),
  ],
})

How It Works

The plugin automatically:

  1. Detects localized fields - Works with both localized: true and regular fields
  2. Copies values - Takes slug and fullPath values and copies them to localizedSlugs
  3. Creates a computed field - Stores the localized slugs for easy access
  4. Prevents infinite loops - Uses internal flags to prevent multitenant recursion

Example Output

Input Collection:

{
  name: 'slug',
  type: 'text',
  localized: true,  // Must be localized!
}
{
  name: 'fullPath',
  type: 'text',
  localized: true,  // Must be localized!
}

Output Document:

{
  "slug": {
    "en": "contact-us",
    "cs": "kontaktujte-nas"
  },
  "fullPath": {
    "en": "/contact-us",
    "cs": "/kontaktujte-nas"
  },
  "localizedSlugs": {
    "en": {
      "slug": "contact-us",
      "fullPath": "/contact-us"
    },
    "cs": {
      "slug": "kontaktujte-nas",
      "fullPath": "/kontaktujte-nas"
    }
  }
}
    {
      collection: 'pages',
      slugField: 'urlSlug',
      generateFromTitle: true,
      titleField: 'pageTitle',
    },
  ],
  enableLogging: true,
}),

], })


## Configuration

### Plugin Options

```typescript
interface LocalizedSlugsPluginOptions {
  /** Whether the plugin is enabled (default: true) */
  enabled?: boolean

  /** Array of supported locales (default: ['cs', 'en']) */
  locales?: ('cs' | 'en')[]

  /** Default locale (default: 'cs') */
  defaultLocale?: 'cs' | 'en'

  /** Collections configuration */
  collections?: CollectionConfig[]

  /** Enable console logging (default: false) */
  enableLogging?: boolean

  /** Custom diacritics mapping for slug generation */
  customDiacriticsMap?: Record<string, string>
}

Collection Configuration

interface CollectionConfig {
  /** Collection slug */
  collection: string

  /** Field name for the slug (default: 'slug') */
  slugField?: string

  /** Field name for the full path (default: 'fullPath') */
  fullPathField?: string

  /** Auto-generate slugs from title field (default: false) */
  generateFromTitle?: boolean

  /** Title field name for auto-generation (default: 'title') */
  titleField?: string
}

How It Works

Slug Generation

The plugin automatically generates URL-friendly slugs from titles:

  • Converts text to lowercase
  • Removes diacritics (ž → z, č → c, etc.)
  • Replaces spaces and special characters with hyphens
  • Removes duplicate hyphens
  • Trims leading/trailing hyphens

Example:

"Čeština" → "cestina"
"Hello World" → "hello-world"
"C++ Programming" → "c-programming"

Localized Slugs

Each locale gets its own slug based on the localized title:

// In your collection:
{
  title: {
    cs: "Přispívání",
    en: "Contributing"
  },
  slug: {
    cs: "prispivani",      // Auto-generated
    en: "contributing"     // Auto-generated
  }
}

Full Path Generation

For hierarchical collections (e.g., pages with parents), the plugin generates full paths:

// Parent: /docs
// Child with slug "guides" → /docs/guides
{
  slug: "guides",
  fullPath: "/docs/guides"  // Auto-generated
}

Extending Locales

To add custom locales beyond Czech and English:

import { localizedSlugsPlugin } from '@kilivi/payloadcms-localized-slugs'

localizedSlugsPlugin({
  locales: ['cs', 'en', 'sk'], // Add Slovak
  defaultLocale: 'cs',
  customDiacriticsMap: {
    š: 's',
    ž: 'z',
    ť: 't',
    ľ: 'l',
  },
  // ... rest of config
})

Custom Diacritics Mapping

Override the default diacritics mapping:

localizedSlugsPlugin({
  customDiacriticsMap: {
    á: 'a',
    é: 'e',
    í: 'i',
    ó: 'o',
    ú: 'u',
    ü: 'u',
  },
})

Integration with Collections

Basic Collection Setup

export const Posts: CollectionConfig = {
  slug: 'posts',
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
      localized: true,
    },
    {
      name: 'slug',
      type: 'text',
      localized: true,
      admin: {
        description: 'Auto-generated from title. Edit to customize.',
      },
    },
    {
      name: 'content',
      type: 'richText',
      localized: true,
    },
  ],
}

Hierarchical Collection (with Parent)

export const Pages: CollectionConfig = {
  slug: 'pages',
  fields: [
    {
      name: 'parent',
      type: 'relationship',
      relationTo: 'pages',
      required: false,
    },
    {
      name: 'title',
      type: 'text',
      localized: true,
      required: true,
    },
    {
      name: 'slug',
      type: 'text',
      localized: true,
    },
    {
      name: 'fullPath',
      type: 'text',
      localized: true,
      admin: {
        readOnly: true,
        description: 'Full URL path (auto-generated)',
      },
    },
  ],
}

API Reference

createLocalizedSlugField

Creates a localized slug field configuration:

import { createLocalizedSlugField } from '@kilivi/payloadcms-localized-slugs/fields'

const slugField = createLocalizedSlugField({
  locales: ['cs', 'en'],
  defaultLocale: 'cs',
})

createPopulateLocalizedSlugsHook

Creates a hook for automatic slug generation:

import { createPopulateLocalizedSlugsHook } from '@kilivi/payloadcms-localized-slugs/hooks'

const beforeChangeHook = createPopulateLocalizedSlugsHook({
  slugField: 'slug',
  titleField: 'title',
  locales: ['cs', 'en'],
})

Examples

Blog with Localized Posts

import { localizedSlugsPlugin } from '@kilivi/payloadcms-localized-slugs'

export default buildConfig({
  collections: [
    {
      slug: 'posts',
      fields: [
        { name: 'title', type: 'text', localized: true },
        { name: 'slug', type: 'text', localized: true },
        { name: 'content', type: 'richText', localized: true },
      ],
    },
  ],
  plugins: [
    localizedSlugsPlugin({
      locales: ['cs', 'en'],
      collections: [
        {
          collection: 'posts',
          generateFromTitle: true,
        },
      ],
    }),
  ],
})

Documentation Site with Hierarchy

localizedSlugsPlugin({
  locales: ['cs', 'en'],
  collections: [
    {
      collection: 'docs',
      slugField: 'slug',
      fullPathField: 'urlPath',
      generateFromTitle: true,
      titleField: 'title',
    },
  ],
})

Troubleshooting

Slugs Not Auto-Generating

  • Ensure generateFromTitle: true in collection config
  • Check that the titleField matches your field name
  • Verify the title field is localized: true

Diacritics Not Converting Correctly

  • Provide a customDiacriticsMap for unsupported characters
  • Check the locale matches your content

Full Paths Not Generating

  • Ensure the collection has a parent relationship field
  • Verify fullPathField matches your field name
  • Full paths only generate for hierarchical collections

Client-Side Usage

The plugin provides client components for use in your Next.js frontend application.

Installation in Next.js App

// app/layout.tsx
'use client'

import { SlugProvider } from '@kilivi/payloadcms-localized-slugs/client'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <SlugProvider>
          {children}
        </SlugProvider>
      </body>
    </html>
  )
}

Using Client Components

// app/[locale]/posts/[slug]/page.tsx
import { ClientSlugHandler } from '@kilivi/payloadcms-localized-slugs/client'

export default async function PostPage({ params }) {
  const post = await getPayloadData('posts', params.slug)

  return (
    <div>
      <ClientSlugHandler localizedSlugs={post.localizedSlugs} />
      <h1>{post.title}</h1>
    </div>
  )
}

Language Switcher Example

'use client'

import { useSlugContext } from '@kilivi/payloadcms-localized-slugs/client'
import Link from 'next/link'

export function LanguageSwitcher() {
  const { state } = useSlugContext()
  const { localizedSlugs } = state

  return (
    <nav>
      {Object.entries(localizedSlugs).map(([locale, slug]) => (
        <Link key={locale} href={`/${locale}/${slug}`}>
          {locale.toUpperCase()}
        </Link>
      ))}
    </nav>
  )
}

📖 For detailed client component usage, see the Client Components Usage Guide

Performance

  • Slug generation happens on document creation/update via hooks
  • No runtime overhead for reads
  • Scales well with collection size
  • Supports batch operations

License

MIT

Author

Kilián Vít

Contributing

Contributions welcome! Please open an issue or submit a PR.

Changelog

See CHANGELOG.md for version history.

Similar plugins