Building a language selector and links

Having trouble installing Oxygen XML WebHelp? Got a bug to report? Post it all here.
InspectorSpacetime
Posts: 38
Joined: Thu Jul 29, 2021 12:02 pm

Building a language selector and links

Post by InspectorSpacetime »

Hello,

What might be the most effective way to build a working language selector and link system in a WebHelp output? Are there any best practices or recommendations for doing this?

Let's say we want the language selector to be a typical Bootstrap dropdown menu in the header of each page. Selecting another language than the current one should take the user to the corresponding page in the selected language, not just the main page. That's the use case here.

The different language versions are published separately as unique maps (and WebHelp outputs). The output file naming and folder structure is similar for each language, except for the language identifier. So something like this:

docs.company.com/EN/topics/greatproduct_EN.html
docs.company.com/DE/topics/greatproduct_DE.html
etc...

Creating the actual dropdown menu and inserting it in the output is quite easy using one of the XHTML fragment parameters. And for the tiles page, search page and index pages the links can be hard-coded since we know the URL of the pages in each language and there's only one page of each type. So no problem there. (This of course means that we have to use unique fragments to insert the menu for each page type!)

But what about the topic pages? Since the different languages are published as separate maps, and the menu + links are not created from DITA content, I would assume that it's not possible to use any DITA linking mechanism here? Of course we could go through each page after publishing and add the links manually, but that's a lot of work and not an optimal solution. We would need to do that after each time the docs are published, so some kind of automatic link creation mechanism would be great.

Three possibilities come to my mind:

1) Picking up the current URL with JavaScript and doing some string manipulation for it. So basically just replacing every EN with a DE, for example. And then entering the modified strings as href attribute values for each language in the dropdown menu.

2) Using the wh-path2root and wh-out-relpath metadata elements that WebHelp creates for each page. This would also be done with JavaScript and some string manipulation.

3) Creating the links at build time in the XHTML fragment. This would be done using the topic-xpath macros and some string manipulation with XPath.

Or is there some other, more simple and effective way to do this?