decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Use i18n translated fields in slug template tags

Open chromjs opened this issue 4 years ago • 5 comments

Context

  • i18n support:
    • https://www.netlifycms.org/docs/beta-features/#i18n-support
  • Slug template tags
    • https://www.netlifycms.org/docs/configuration-options/#slug

Is your feature request related to a problem? Please describe. I'm not able to define a translated slug for each language using the i18n beta feature, the template tag uses the default language for all of them.

Describe the solution you'd like Template tags should take the value from the field in its respective language ( {{slug}} or {{title}} are the ones I'm looking for)

Additional context This is my config file:

backend:
  name: git-gateway
  branch: master # Branch to update (optional; defaults to master)

local_backend: true

media_folder: static/img
public_folder: /img

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

collections:
  - name: "items"
    label: "Items"
    folder: "content/items"
    create: true
    slug: "{{title}}"
    # slug: "{{slug}}"
    media_folder: ""
    public_folder: ""
    i18n: true
    editor:
      preview: false
    fields:
      - { label: "Title", name: "title", widget: "string", i18n: true }

Then I publish a new "Item" with the following titles:

  • Mi artículo
  • My item

And it generates the following files:

.
├── en
│   └── mi-artículo.md
└── es
    └── mi-artículo.md

chromjs avatar Jun 12 '21 20:06 chromjs

Can I pick this up?

T0shik avatar Oct 23 '21 12:10 T0shik

Thanks @T0shik, the slug is computed in https://github.com/netlify/netlify-cms/blob/bf8b94f0117fde88a213c6cd6fa4bcb8b5f1c194/packages/netlify-cms-core/src/lib/formatters.ts#L114

erezrokah avatar Oct 25 '21 09:10 erezrokah

Sorry for the delays, after having a hand at this, this seems a bit trickier to accomplish than it seems.

What we want to have is for the user to be able to visit ether:

  1. site.com/en/english
  2. site.com/es/espanol

with their respective .md files

  1. items/en/english.md
  2. items/es/espanol.md

at the moment we store the .md files as:

  1. items/en/english.md
  2. items/es/english.md

this is because when you initially create the record on the admin panel, the slug is english (for the main locale) and when you want to re-edit the record as an admin you need to re-navigate to the /edit/english

The problem is not being able to change the created files, the problem is finding them again on the admin side.

if the files are stored as

  1. items/en/english.md
  2. items/es/espanol.md

they show up as a single item on the ui, under the english slug. Because actual translation isn't performed I don't see how we can find the items/es/espanol.md record based on english slug.

  • After having some time to think maybe have something like: items/<id>/<locale>/<slug>.md, so admin can edit on /admin/<id>, and for the user when we query we flatten out the folder as if it doesn't exist.
  • Maybe a bit less neat solution would be: items/<locale>/<id>;<slug>.md but seems like less change.

T0shik avatar Nov 13 '21 22:11 T0shik

any news on this topic? I really like the i18n feature, but the fact that files are always saved in the default language makes it very hard to use, when the goal is to have translated urls in the end.

could help out if needed, would love to see the feature in near future

wireless25 avatar Apr 15 '22 17:04 wireless25

To add to this, with Hugo the locale slug can be as such {{slug}}.{{locale}}.md

Reference: https://gohugo.io/content-management/multilingual/

OiYouYeahYou avatar Jul 16 '22 12:07 OiYouYeahYou