Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brendanAx opened this issue Nov 20, 2022 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@brendanAx
Copy link

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,
        }

@brendanAx brendanAx added the type: bug code to address defects in shipped code label Nov 20, 2022
@stale
Copy link

stale bot commented Apr 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants