-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
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:
The filename of both locales will be en-lorem.md
:
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)
- Add a folder collection with
i18n
option enabled. - Add a
slug
field to the collection and reference the field in the collection'sslug
option:slug: {{fields.slug}}
. - Add top-level config for i18n with 2 locales, e.g.
en
&pt
. - Open the control panel, create a new page with distinct slug field values for each locale, e.g.
en-lorem
,pt-lorem
. - Publish the page.
- 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,
}