question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use i18n translated fields in slug template tags

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
wireless25commented, Apr 15, 2022

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

2reactions
T0shikcommented, 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 <id> 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.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Translation | Django documentation
Translations in Django templates uses two template tags and a slightly different syntax than in Python code. To give your template access to...
Read more >
How do you translate the slug value of a page? - Stack Overflow
It has been long but I'm going to post an answer anyway, the best way to get rid of the different slugs problem...
Read more >
i18n in model fields - FuelPHP forums
My first idea is to store each fields that require translations in another table, category_lang (with fields id, lang, slug, label, summary, details),...
Read more >
Gatsby i18n: A Hands-on Guide | Phrase
Note the slug field in the front matter, as we'll use it for our dynamic routing in a minute. blog/courage-after-greatness/index.mdx.
Read more >
Multilingual slug setup - Craft CMS Stack Exchange
For a multi locale setup with translated slugs it's recommended to not rely on "URI to template matching" at all and create an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found