Handling Multiple coding language code inserts

This forum is for all Flare issues not related to any of the other categories.
Post Reply
yonatanlehman
Propeller Head
Posts: 51
Joined: Mon Sep 18, 2017 6:14 am

Handling Multiple coding language code inserts

Post by yonatanlehman »

Hi
I'm documenting a tool that has SDK in multiple programming languages (Java, Javascript, Ruby, C++ and more).
I have two challenges:
1. Giving example code for each of the languages. While I could certainly always give every code example in all languages, perhaps using text dropdowns to hide the details, I would prefer to always show only one language, chosen by the user either globally, or by using some sort of "radio" buttons on each page. My idea is to do this with Javascript but I'm wondering if someone has already done this and found a convenient way to organize all the information.

2. The API definition of functions/methods. Much of the API definition, such as the overall description, and the semantics of function arguments are programing language independent. I want to be able to share them, between the various languages specific descriptions. I can use snippets - but I'm talking of say about 100 methods and 10 languages, I suspect that using snippets would be clumsy or hard to manage.

I'd be happy to hear any ideas how you approached these challenges with Flare or perhaps other tools. Would Lingo help here?
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: Handling Multiple coding language code inserts

Post by NorthEast »

How's your javascript?

I can suggest an approach.

* Create a condition for each language, and mark the content with that condition. Although you're not setting that condition in the target, it'll be included in the output HTML as data-mc-conditions="xxx.yyy"

* Add a control that lets the user select the version to display, and use a script to hide/show the appropriate content. This would use CSS to only show content with the appropriate condition (data-mc-conditions="xxx.yyy").
For an example, see this blog post by Thomas Tregner: tregner.com/flare-blog/version-filters-in-html5-output/

* If you want to save/persist the user's choice when moving between pages (or different sessions), then you need a bit more javascript to store and read that information, and use it to pre-select the correct option. To do this, I'd suggest looking at "local storage", which is a bit like cookies and lets you save data for a user on that browser. You'll find plenty examples of how store/read data - it's not difficult, but you will need to get stuck in to some javascript.


If that sounds a bit much for you to do yourself, then try and get help from a developer. I did something similar in a single day, with about 2hr help from a developer. It's not actually that difficult for someone who knows what they're doing!
Post Reply