Hi, This is my first post on the forum. I’m updating the API documentation for 1QBit and would like to end up with sample code with a selector for different languages. For example:
Does anyone have a recommendation of how to set up the data structure in Contentful to achieve this? Should I create a Long Text field for each language? Should I have one big Long Text field and include all the sample code there distinguished by code block language, for example, ```python?
Hello and welcome to our forums!
We have faced a similar issue when creating the example apps: Link to the example app, written in java.
We solved it by having a field for every language:
By using this content model:
and it results to this json response:
"en-US": "Fetch all entries > code"
"en-US": "curl -H 'Authorization: Bearer '$CDA_TOKEN 'https://cdn.contentful.com/spaces/'$SPACE_ID'/entries/'"
"en-US": "var entry = await client.GetEntries<dynamic>();\n\nConsole.WriteLine(entry.ToString());"
"en-US": "client.getEntries()\n.then((response) => console.log(response))"
"en-US": "final CDAArray all =\n client\n .fetch(CDAEntry.class)\n .all();\n\nSystem.out.println(all);\n"
Feel free to check out the source code of the apps here: https://github.com/contentful/the-example-app.java (Other languages are also available: use
csharp intead of
I hope I could help you and am looking forward to hear from you again,
Thanks, @mario. Have you also explored the use of locales before choosing this method by any chance?
Never mind. I was playing with locales and I just found out that you can only select human languages when creating a new one. So, it won’t work for code languages.