diff options
Diffstat (limited to 'src/locale/load-messages.sh.in')
-rw-r--r-- | src/locale/load-messages.sh.in | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/locale/load-messages.sh.in b/src/locale/load-messages.sh.in new file mode 100644 index 0000000..6a3ffef --- /dev/null +++ b/src/locale/load-messages.sh.in @@ -0,0 +1,35 @@ +#!/bin/sh +set -eu + +get_lang() { + # LC_MESSAGES="ll_CC.CODESET@modifier" -> ll_CC, where quotes are + # optional + locale 2>/dev/null | + grep ^LC_MESSAGES | + cut -d. -f1 | + cut -d\" -f2 | + cut -d= -f2 +} + +locpath() { + lang="$1" + printf '@LOCALEDIR@/%s/LC_MESSAGES/@NAME@/%s.sh' "$lang" "$lang" +} + +ll_CC="$(get_lang)" +ll="$(echo "$ll_CC" | cut -d_ -f1)" + +if [ -r "$(locpath "$ll")" ]; then + # shellcheck source=/dev/null + . "$(locpath "$ll")" +fi + +if [ -r "$(locpath "$ll_CC")" ]; then + # shellcheck source=/dev/null + . "$(locpath "$ll_CC")" +fi + +# locale hierarchy: +# 1. the language+country specific message +# 2. the language specific message +# 3. the default fallback value |