Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active January 21, 2021 14:19
Show Gist options
  • Save turboBasic/1c6137084bff52eb598225a32983e37b to your computer and use it in GitHub Desktop.
Save turboBasic/1c6137084bff52eb598225a32983e37b to your computer and use it in GitHub Desktop.
Get detailed difference between two locales #locale #linux
#!/usr/bin/env bash
locale1=${1:-uk_UA.UTF-8}
locale2=${2:-ru_UA.UTF-8}
shopt -s nocasematch
if [[ $locale1 != POSIX ]] \
&& [[ ! $locale1 =~ ' '$ ]] \
&& [[ ! $locale1 =~ @.+$ ]] \
&& [[ ! $locale1 =~ \.utf-?8$ ]]
then
locale1+=".UTF-8"
fi
if [[ $locale2 != POSIX ]] \
&& [[ ! $locale2 =~ ' '$ ]] \
&& [[ ! $locale2 =~ @.+$ ]] \
&& [[ ! $locale2 =~ \.utf-?8$ ]]
then
locale2+=".UTF-8"
fi
locale1="${locale1%% *}"
locale2="${locale2%% *}"
printf 'Diff between %s and %s\n---\n' "$locale1" "$locale2"
for category in LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME \
LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME
do
printf '\n\n%s:\n' $category
diff <( env "$category=$locale1" locale --category-name --keyword-name $category ) \
<( env "$category=$locale2" locale --category-name --keyword-name $category )
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment