#!/bin/sh
+# Set LANGUAGE_DEFAULT to enable Plugin
+[ ! "$LANGUAGE_DEFAULT" ] && return 1
+
export LANGUAGE_DEFAULT="${LANGUAGE_DEFAULT:-en}"
export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}"
+export LANGUAGE=''
+
+mdfile(){
+ # Override mdfile Selection from tools.sh
+ local page="$(PATH "$1")"
+ page="${page%/}"
+
+ # Additional part:
+ # if PAGE Address is LANGUAGE Page, jump to regular processing
+ # else if LANGUAGE Page exists, add language tag
+ # Also the reason why `mdfile` should not be used in `acl.sh`
+ if [ "${page%/:${LANGUAGE}}" != "$page" ]; then
+ :
+ elif [ -f "$_DATA/pages/$page/:$LANGUAGE/#page.md" ]; then
+ printf %s\\n "$_DATA/pages/$page/:$LANGUAGE/#page.md"
+ return 0
+ elif [ -f "$_EXEC/pages/$page/:$LANGUAGE/#page.md" ]; then
+ printf %s\\n "$_EXEC/pages/$page/:$LANGUAGE/#page.md"
+ return 0
+ fi 2>&-
+
+ # Regular processing, keep in sync with tools.sh
+ if [ -f "$_DATA/pages/$page/#page.md" ]; then
+ printf %s\\n "$_DATA/pages/$page/#page.md"
+ return 0
+ elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
+ printf %s\\n "$_EXEC/pages/$page/#page.md"
+ return 0
+ else
+ return 1
+ fi 2>&-
+ # ^^ suppress error messages produced
+ # by printf when stdout was closed
+}
case ${HTTP_REFERER} in
*/:*/*):;;
;;
esac
-export LANGUAGE="${LANGUAGE_REFERRED:-${LANGUAGE_DEFAULT}}"
+LANGUAGE="${LANGUAGE_REFERRED:-${LANGUAGE_DEFAULT}}"
case ${PATH_INFO} in
*/:?*/\[attachment\]/?*)
- export LANGUAGE="${PATH_INFO#*/:}"
- LANGUAGE="${LANGUAGE%%/*}"
+ LANGUAGE="${PATH_INFO#*/:}"
+ LANGUAGE="${LANGUAGE%%/*}"
PATH_INFO="${PATH_INFO%%:?*/*}${PATH_INFO#*/:?*/}"
;;
*/:?*/\[attachment\])
- export LANGUAGE="${PATH_INFO#*/:}"
- LANGUAGE="${LANGUAGE%%/*}"
+ LANGUAGE="${PATH_INFO#*/:}"
+ LANGUAGE="${LANGUAGE%%/*}"
PATH_INFO="${PATH_INFO%:?*/\[attachment\]}[attachment]"
;;
- */:*/?*) # Never occurs
- :;;
+ */:?*/\[*\])
+ :;; # Default handler, considered valid in most cases
+ */:?*/?*)
+ :;; # Default attachment handler
*/:?*/) # Faulty URL build
REDIRECT "${_BASE}${PATH_INFO%/}"
;;
# REDIRECT "${_BASE}${PATH_INFO%:*}"
# ;;
*/:?*)
- export LANGUAGE="${PATH_INFO##*/:}"
+ LANGUAGE="${PATH_INFO##*/:}"
+
if mdfile "${PATH_INFO}/"; then
+ # Pretend to deliver Language Page, if Language Tag is valid
PATH_INFO="${PATH_INFO}/"
elif [ "$LANGUAGE" = "$LANGUAGE_DEFAULT" ]; then
+ # Pretend Language Tag was omitted for default Language
PATH_INFO="${PATH_INFO%:*}"
else
- export ERROR_MSG="TRANSLATION NOT FOUND"
+ # Deliver default Page if Language is not found
+ ERROR_MSG="TRANSLATION NOT FOUND"
PATH_INFO="${PATH_INFO%:*}"
fi
;;
- /|*/*/)
+ /|*/*/) # Keep Language from Referer
if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
REDIRECT "${_BASE}${PATH_INFO}:${LANGUAGE_REFERRED}"
fi
;;
- */:*/\[*\]) # Considered valid in most cases
- :;;
- */\[*\])
+ */\[*\]) # Keep Language from Referer
if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
REDIRECT "${_BASE}${PATH_INFO%\[*\]}:${LANGUAGE_REFERRED}/[${PATH_INFO##*/\[}"
fi