3 # Copyright 2023 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 _(){ printf %s\\n "$*"; }
19 # Set LANGUAGE_DEFAULT to enable Plugin
20 [ ! "$LANGUAGE_DEFAULT" ] && return 1
22 export LANGUAGE_DEFAULT="${LANGUAGE_DEFAULT:-en}"
23 export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}"
24 export LANGUAGE ERROR_MSG
26 case ${HTTP_REFERER} in
29 LANGUAGE_REFERRED="${HTTP_REFERER##*/:}"
33 LANGUAGE="${LANGUAGE_REFERRED:-${LANGUAGE_DEFAULT}}"
36 */:?*/\[attachment\]/?*)
37 LANGUAGE="${PATH_INFO#*/:}"
38 LANGUAGE="${LANGUAGE%%/*}"
39 PATH_INFO="${PATH_INFO%%:?*/*}${PATH_INFO#*/:?*/}"
42 LANGUAGE="${PATH_INFO#*/:}"
43 LANGUAGE="${LANGUAGE%%/*}"
44 PATH_INFO="${PATH_INFO%:?*/\[attachment\]}[attachment]"
47 LANGUAGE="${PATH_INFO#*/:}"
48 LANGUAGE="${LANGUAGE%%/*}"
51 # Accidental double language link, last one stays valid!
52 REDIRECT "${_BASE}${PATH_INFO%/:?*/:?*}/:${PATH_INFO##*/:}"
55 :;; # Default attachment handler
56 */:?*/) # Faulty URL build
57 REDIRECT "${_BASE}${PATH_INFO%/}"
59 # */:"${LANGUAGE_DEFAULT}")
60 # REDIRECT "${_BASE}${PATH_INFO%:*}"
63 LANGUAGE="${PATH_INFO##*/:}"
64 PATH_INFO="${PATH_INFO%:*}"
66 [ "$LANGUAGE" != "$LANGUAGE_DEFAULT" ] \
67 && case "$(mdfile "${PATH_INFO}")" in
68 *"/:$LANGUAGE/#page.md")
72 *)ERROR_MSG="TRANSLATION NOT FOUND"
76 /|*/*/) # Keep Language from Referer
77 if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
78 REDIRECT "${_BASE}${PATH_INFO}:${LANGUAGE_REFERRED}"
81 */\[*\]) # Keep Language from Referer
82 if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
83 REDIRECT "${_BASE}${PATH_INFO%\[*\]}:${LANGUAGE_REFERRED}/[${PATH_INFO##*/\[}"
88 [ -r "${_EXEC}/l10n/${LANGUAGE}.sh" ] && . "${_EXEC}/l10n/${LANGUAGE}.sh"