0

I have a Jekyll website with a Netlify CMS admin page. The website supports some different languages, which I have in a _data/languages.yml file for Jekyll to use. Then in the Netlify backend there is a select widget with those same languages.

However, this means I have some duplication of this data, both my languages.yml file and the config.yml file of Netlify have the same list of languages. So I was wondering, is there a way to only have this list of languages once?

My _data/languages.yml file looks something like this:

- value: "nl"
 label: "NL"
- value: "en"
 label: "EN"
- value: "fr"
 label: "FR"
- value: "de"
 label: "DE"
- value: "ja"
 label: "Japanese"
- value: "zh"
 label: "Mandarin"

And in the Netlify config.yml there is:

...
 label: 'Language'
 name: 'language'
 widget: 'select'
 options: 
 - { label: "Dutch", value: "nl" }
 - { label: "English", value: "en" }
 - { label: "French", value: "fr" }
 - { label: "German", value: "de" }
 - { label: "Japanese", value: "ja" }
 - { label: "Chinese", value: "zh" }
...

What I thought of (and why it doesn't work):

  1. Use liquid tags inside the config.yml -> This is not supported, and Netlify just complains that the config.yml now starts with --- --- (the frontmatter)
  2. Include the languages.yml inside config.yml -> You can't "import" yml files in another one sadly

Are there any other ways that do work?

asked Jan 11, 2023 at 15:03

1 Answer 1

1

You can make your languages a file collection, which will then allow you to use a relation widget instead of the select widget with the hardcoded languages you're currently using.

If you don't want your admin user to be able to edit this language list, you can use the hide: true option in your language collection.

answered Jan 11, 2023 at 19:39
Sign up to request clarification or add additional context in comments.

4 Comments

Brilliant! I'm going to try this, and it's ok that they can add languages.
Question, it looks like I'll have to make a different file for each language, is that correct? If not, how do I set up the relation widget to look at the list in a single file?
It should work without different files, as then it would just be a folder collection. Just need to figure out the correct syntax for the relation widget :D
Found it! There is an example for how to reference a file collection in the relation widget docs: netlifycms.org/docs/widgets/#relation

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.