From f621613128000d0b89abcf9658c80efdc3b6c38b Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 21 Jun 2021 20:01:08 -0300 Subject: src/git-permalink.sh: Use LC_MESSAGES to decide on the language First, instead of looking at "${LANG:-}" for choosing the language, we now use LC_MESSAGES from the locale(1) command. LC_MESSAGES is the appropriate place to look at, and it inherits the value of $LANG by default, but can be overriden so that the text messages from a program spits out strings from a language, but use everything else from $LANG (such as LC_NUMERIC), like in: LANG=abc LC_MESSAGES=zzz I took this opportunity to look only at the language and country part of the locale, and not at the codeset or modifier (as in ll_CC.CODESET@modifier), so that as long as the language+country is the same, it uses the according message. This addresses the "Maybe it could be less restrictive of country or encoding" comment on --- src/git-permalink.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/git-permalink.sh') diff --git a/src/git-permalink.sh b/src/git-permalink.sh index d1edbba..f894b62 100755 --- a/src/git-permalink.sh +++ b/src/git-permalink.sh @@ -60,14 +60,23 @@ MSG_OPEN=\$MSG_OPEN_$lang " } -case "${LANG:-}" in - pt_BR.UTF-8*) +get_lang() { + # LC_MESSAGES="ll_CC.CODESET@modifier" -> ll_CC, where quotes are optional + locale | \ + grep LC_MESSAGES | \ + cut -d. -f1 | \ + cut -d\" -f2 | \ + cut -d= -f2 +} + +case "$(get_lang)" in + pt*) set_lang PT ;; - fr_FR.UTF-8*) + fr*) set_lang FR ;; - eo.UTF-8*) + eo*) set_lang EO ;; *) -- cgit v1.2.3