At least macOS and FreeBSD use the "raw" form.
But note that Linux uses the raw from as well for the "C.UTF-8" locale
and not the transformed "C.utf8", so add an exception for this case.
lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
lc_messages=$lc_messages:gs/\"//
locale=$lc_messages:r
lc_messages=$(locale 2>/dev/null | fgrep LC_MESSAGES | cut -d'=' -f2)
lc_messages=$lc_messages:gs/\"//
locale=$lc_messages:r
- encoding=$lc_messages:e:l:gs/-//
+ [[ "$OSTYPE" = 'linux-gnu' && $locale != 'C' ]] \
+ && encoding=$lc_messages:e:l:gs/-// \
+ || encoding=$lc_messages:e
[[ -n "$encoding" ]] && locale="$locale.$encoding"
[[ -z "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && unset lc_messages
[[ -n "$encoding" ]] && locale="$locale.$encoding"
[[ -z "$LANG$LANGUAGE$LC_ALL$LC_MESSAGES" ]] && unset lc_messages