[type/__localdef] Also check for aliases in state explorer

This commit is contained in:
Dennis Camera 2020-11-14 10:41:50 +01:00
parent eeb9871919
commit 87faffd875
2 changed files with 35 additions and 3 deletions

View File

@ -25,8 +25,14 @@
# the main locale (and possibly aliases) is present # the main locale (and possibly aliases) is present
# absent: # absent:
# neither the main locale nor any aliases are present # neither the main locale nor any aliases are present
# alias-present:
# the main locale is absent, but at least one of its aliases is present
# #
# Hardcoded, create a pull request in case it is at another location for
# some other distro. (cf. gencode-remote)
aliasfile='/usr/share/locale/locale.alias'
command -v locale >/dev/null 2>&1 || exit 0 command -v locale >/dev/null 2>&1 || exit 0
locales=$(locale -a) locales=$(locale -a)
@ -68,4 +74,27 @@ locale_available() (
} }
) )
locale_available "${__object_id:?}" && echo present || echo absent if locale_available "${__object_id:?}"
then
echo present
else
# NOTE: locale.alias can be symlinked.
if test -e "${aliasfile}"
then
# Check if one of the aliases of the locale is defined
baselocale=$(
parse_locale "${__object_id:?}" _lang _codeset _modifiers \
&& format_locale "${_lang}" "${_codeset}")
while read -r _alias _localename
do
if test "${_localename}" = "${baselocale}" \
&& echo "${locales}" | grep -qxF "${_alias}"
then
echo alias-present
exit 0
fi
done <"${aliasfile}"
fi
echo absent
fi

View File

@ -94,9 +94,12 @@ in
localedef --delete-from-archive "\${_alias}" localedef --delete-from-archive "\${_alias}"
fi fi
done <'${aliasfile}' done <'${aliasfile}'
localedef --delete-from-archive '${main_localename}'
EOF EOF
if test "${state_is}" = present
then
printf "localedef --delete-from-archive '%s'\n" "${main_localename}"
fi
;; ;;
esac esac
;; ;;