decaporg / decaporg/decap-cms

Hugo's translationKey support for i18n paths

Open
#4,645 5 comments 1 reaction 0 assignees View on GitHub
area: i18n pinned type: feature
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Is your feature request related to a problem? Please describe.**

I'm trying to find a way to get netlify-cms to understand French/English page pairs in different subfolders. I'm working with Hugo, and the way they handle translation of paths is to provide a **translationKey** frontmatter field that links two pages in differently named folders.

Given the following file structure:
```
src
├── content
│ ├── en
│ │ └── resources
│ │ └── index.md
│ └── fr
│ └── ressources
│ └── index.md
```
with frontmatter for the **en** one like:
```md
---
title: Resources
slug: resources
date: 2020-10-30T14:33:09.744Z
translationKey: resources
---
```
vs the **fr** one:
```md
---
title: Ressources
slug: ressources
date: 2020-10-30T14:33:09.744Z
translationKey: resources
---
```
and the following netlify-cms config.yml:
```yaml
.
.
.
i18n:
structure: multiple_folders
locales: [en, fr]
collections:
- name: 'page'
label: 'page'
folder: '/src/content'
i18n: true
create: true
editor:
preview: true
nested:
depth: 100 # max depth to show in the collection tree
summary: '{{title}}' # optional summary for a tree node, defaults to the inferred title field
fields:
- { label: 'Title', name: 'title', i18n: true, widget: 'string' }
- { label: 'Path', name: 'slug', i18n: true, widget: 'string', required: false }
- { label: 'Meta description', name: 'description', required: false, i18n: true, widget: 'string' }
- { label: 'Publish Date', name: 'date', i18n: true, widget: 'datetime' }
- { label: 'Translation key', name: 'translationKey', required: false, i18n: true, widget: 'hidden', default: '{{slug}}' }
- { label: 'Body', name: 'body', i18n: true, widget: 'markdown' }
```
Netlify-cms sees them as unrelated pages:
![image](https://user-images.githubusercontent.com/1659632/100466073-50977000-309e-11eb-81e1-7837091713d1.png)
and
![image](https://user-images.githubusercontent.com/1659632/100466124-67d65d80-309e-11eb-81f5-ecee0cf74671.png)

Likewise when creating content. I fill out the English and French sides of the editor, adding different path values, and get pages with this kind of frontmatter:

**src/content/en/covid-19.md**
```md
---
title: Covid-19
slug: covid
description: ""
date: 2020-11-27T14:44:25.843Z
translationKey: "{{slug}}"
---
```
and
**src/content/en/covid-19.md**
```md
---
title: Covid-19
slug: covid
date: 2020-11-27T14:44:25.859Z
translationKey: "{{slug}}"
---
```
(not sure why description doesn't show up in the French file, but that's another issue).

The `{{slug}}` part isn't being resolved as expected. I'd expect to see **covid** there.

**Describe the solution you'd like**

I'd like to see 2 things:

1. The collections browser should use frontmatter like **translationKey** (for Hugo; not sure what equivalents are for other frameworks) to match translated files.
2. The widgets like **string** and **hidden** should support parsing template tags like `{{slug}}`.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the collections browser's translation matching and the string and hidden widgets' handling of template tags. Reproduce the Hugo multiple_folders example with translationKey and {{slug}} values. Done means translated files are grouped by the frontmatter key and template values resolve to the expected slug.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
content, frontend, internationalization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.