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

Use i18n translated fields in slug template tags #5493

Open
saulchavezr opened this issue Jun 12, 2021 · 5 comments
Open

Use i18n translated fields in slug template tags #5493

saulchavezr opened this issue Jun 12, 2021 · 5 comments
Assignees
Labels
area: i18n good first issue type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@saulchavezr
Copy link

Context

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
@saulchavezr saulchavezr added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jun 12, 2021
@T0shik
Copy link

T0shik commented Oct 23, 2021

Can I pick this up?

@erezrokah
Copy link
Contributor

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

@T0shik
Copy link

T0shik commented Nov 13, 2021

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.

@wireless25
Copy link

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

@OiYouYeahYou
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: i18n good first issue type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

5 participants