XWiki in 2 languages with a Left Panel Selector

Hello,

I was annoyed at first, because the XWiki I put up for Linuxvillage was staying in French, although, Multilingual was selected, in the Internationalisation page, and I had both Français and English British as languages selected.

The default was French. Looking more closely at the documentation page, (the one in the blog, in French - Comment changer la langue par défaut d'XWiki et rendre le wiki multilingue - XWiki), there was this screenshot with English as the default, and I thought, why not give it a try?.

That did the trick.

Still, having the choice for the default language hidden in the drawer language submenu was not to my liking. I think, people should be able to find it at the first glance when reaching the Home page.

I asked help to an AI. At some point I suggested I’d use a macro, and the AI provided code : many iterations! I was testing, providing it feedback, and at the end, just when I was about to get too infuriated to continue, the right code for the macro, and for the panel page was there!

So, I’d like to share.

To get a new panel above the Navigation menu:

Go to Administer Wiki > Look & Feel > Panels.

In the body, once selected Panels, under the option Panels displayed on the left, add : Panels.Languages before Panels.Navigation.
Click on the blue button down the page to save the modification. Here is a small screenshot.

For the Macro, in the Macro page, I created a new Object, then created the page LanguageSelectorMacro, selected WikiMacroClass, then the full page needed configuration, and code.

(I really should have been in the “Home / Macros” to show this, before actually creating the page).

The code for the macro, which is at work now:

{{velocity}}
#set ($currentUrl = $xcontext.request.requestURL.toString().replaceAll("\?.*", ""))

[[🇫🇷 Français>>$currentUrl?language=fr]] | [[🇬🇧 English>>$currentUrl?language=en]]
{{/velocity}}

This provides visible flags, in Firefox, and “FR” and “GB” tags, in Chromium.

In the last field, “Elements of the request”, I selected “Language” and “URL of the request”.

The rest of the fields can be viewed in the next screenshot.

The other page which needs to be created is a Panel.
I want it to come before “Navigation”, on the left sidebar, which means, at the top left.

In the Panels page, I created a “Languages” sub-page. (“/bin/edit/Panels/Languages”)

  • Type of panel “view”
  • Category “Navigation”
  • Description “Choix de la langue”
  • Content:

 == Langues / Languages==

{{languageSelector /}}

  • Asynchronus rendering “No”
  • Cache “No”
  • Elements of context “Langue”

Here’s some simpler and better code (doesn’t involve an external URL and you don’t need context elements) that should hopefully work:

{{velocity}}
[[🇫🇷 Français>>||queryString='language=fr']] | [[🇬🇧 English>>||queryString='language=en']]
{{/velocity}}

Note: I’m assuming that the panel is written in xwiki/2.1 syntax.

WDYM? You were expecting to see a page in English when the default was French? Were you expecting that for some reason? Note that the language selected should be the one defined in your browser.

See also https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/I18N#HSwitchtoanotherlanguage

Why the Home page? Or do you mean on all pages? (your solution with the Panel will display the language option on all pages).

@tkrieck WDYT? Should we move the language selection outside of the drawer, i.e put it next the avatar for ex? Maybe this is something you proposed already?

Thx

Of course I did : I had Multilingual selected, and French and English chosen in the relevant configuration page, as mentioned at the beginning of my post. And I launched a Virtual Machine in Virtualbox, with a Live Linux branded in English, so, the web browser was requesting pages in English, and didn’t have any cache or cookie yet.

Only when I switched the default language to English, it showed pages in the language according to what the web browser setup was. (Did more tests, with private windows in my current installation).

Thank you for the corrected macro, I’ll give it a try whenever I can.

It’s something worth exploring, I need to get a bit more acquainted with multilanguage wikis though.