Use i18n translated fields in slug template tags
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
Can I pick this up?
Thanks @T0shik, the slug is computed in https://github.com/netlify/netlify-cms/blob/bf8b94f0117fde88a213c6cd6fa4bcb8b5f1c194/packages/netlify-cms-core/src/lib/formatters.ts#L114
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:
site.com/en/englishsite.com/es/espanol
with their respective .md files
items/en/english.mditems/es/espanol.md
at the moment we store the .md files as:
items/en/english.mditems/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
items/en/english.mditems/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 thefolder as if it doesn't exist. - Maybe a bit less neat solution would be:
items/<locale>/<id>;<slug>.mdbut seems like less change.
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
To add to this, with Hugo the locale slug can be as such {{slug}}.{{locale}}.md
Reference: https://gohugo.io/content-management/multilingual/