From e22fa5d3d78008f53227014afb6b1a6622d5c1d4 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 14 Sep 2021 22:07:29 -0300 Subject: Rework how translation is done Instead of variables on the code itself, each language gets its own file. --- src/load-locale-messages.sh.in | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/load-locale-messages.sh.in (limited to 'src/load-locale-messages.sh.in') diff --git a/src/load-locale-messages.sh.in b/src/load-locale-messages.sh.in new file mode 100644 index 0000000..4840e0f --- /dev/null +++ b/src/load-locale-messages.sh.in @@ -0,0 +1,33 @@ +#!/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@.sh' "$lang" +} + +ll_CC="$(get_lang)" +ll="$(echo "$ll_CC" | cut -d_ -f1)" + +if [ -r "$(locpath "$ll")" ]; then + . "$(locpath "$ll")" +fi + +if [ -r "$(locpath "$ll_CC")" ]; then + . "$(locpath "$ll_CC")" +fi + +# locale hierarchy: +# 1. the language+country specific message +# 2. the language specific message +# 3. the default fallback value -- cgit v1.2.3