Sometimes one might want to display content according to the language preference of the visitor (as sent to the web server by the browser's Accept-Language header). This JSPWiki plugin does exactly that, selecting from a list of supplied content choices. It would be used like this:

[{LanguagePlugin

:de:German::  :en:English::  :else:no language matches::}]

The result would be "German" if that happens to be the preferred choice, or "English", or "no language matches", if neither language is acceptable to the browser. If the "else" part is missing when no language matches, nothing is displayed.

The code only considers the main language, not regional variants. For example, en-GB and en-US are both treated as "en".

The source code is here. A jar file containing all my JSPWiki plugins is here.


CodeSnippets