Skip to content

i18n: localized "slug" field value cannot be used as a folder collection item's filename #6600

@brendanAx

Description

@brendanAx

Describe the bug
The ability to specify a collection item's filename via a "slug" field, described in the docs here, does not work as expected with i18n enabled: the filename will always be the default locale's slug field value.

For example, if the following page is saved:
image

The filename of both locales will be en-lorem.md:
image

This bug particularly affects projects using web frameworks which employ file-based routing (e.g. Astro, Next.js), as there may not be any viable workarounds without resorting to hardcoding the desired paths via server redirects, etc.

To Reproduce
(See example config added below)

  1. Add a folder collection with i18n option enabled.
  2. Add a slug field to the collection and reference the field in the collection's slug option: slug: {{fields.slug}}.
  3. Add top-level config for i18n with 2 locales, e.g. en & pt.
  4. Open the control panel, create a new page with distinct slug field values for each locale, e.g. en-lorem, pt-lorem.
  5. Publish the page.
  6. Check the saved filenames for the page.

Expected behavior
The values specified in the slug fields should be used as the filenames for their respective locales. E.g. for en, the filename should be en-lorem (working as expected), for pt, the filename should be pt-lorem (not working as expected).

Applicable Versions:

  • Netlify CMS version: 2.10.192

CMS configuration

backend:
  name: git-gateway
  branch: master

media_folder: "public/uploads"
public_folder: "/uploads"

editor:
  preview: false # we're going to hide the preview editor

i18n:
  structure: multiple_folders
  locales: [en, pt]
  default_locale: en

slug:
  encoding: "ascii"
  clean_accents: true

collections:
  - label: "Pages"
    name: "pages"
    folder: "/src/pages"
    create: true
    i18n: true
    slug: "{{fields.slug}}"
    fields:
      - {
          label: "Layout",
          name: "layout",
          widget: "hidden",
          default: "/src/layouts/netlify_cms.astro",
          i18n: duplicate,
        }
      - { label: "Title", name: "title", widget: "string", i18n: true }
      - {
          label: Slug,
          name: slug,
          widget: string,
          hint: "N.B. slug must be different for each locale",
          pattern:
            [
              "^[a-z0-9-]+$",
              "The slug must contain only lower case letters, numbers and hyphens",
            ],
          i18n: true,
        }
      - {
          label: "Body",
          name: "body",
          widget: "text",
          required: false,
          i18n: true,
        }
      - {
          label: "Publish Date",
          name: "date",
          widget: "datetime",
          i18n: duplicate,
        }
      - {
          label: "Featured Image",
          name: "thumbnail",
          widget: "image",
          required: false,
          i18n: duplicate,
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions