/usr/share/language-tools/language2locale is in accountsservice 0.6.40-2ubuntu10.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #!/bin/sh -e
#
# - takes the first choice language in the LANGUAGE priority list as argument
# - outputs locale name corresponding to that language
lang=$1
locale_name=
test -n "$lang" || exit 1
# remove codeset if any
if [ "$lang" != "${lang%.*}" ]; then
lang=$( echo $lang | sed -r 's/([^.]+)[^@]+(.*)/\1\2/' )
fi
langtoolsdir=/usr/share/language-tools
langcode=${lang%%[_@]*}
locales=
for loc in $( locale -a | grep -F .utf8 ); do
# skip locales for other languages
if [ $langcode = ${loc%%[._@]*} ]; then
loc=${loc%.*}${loc#*.utf8}
locales="$locales $loc"
fi
done
# exact match
for loc in $locales; do
if [ $lang = $loc ]; then
locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
break
fi
done
if [ -z "$locale_name" -a $lang = ${lang%_[A-Z]*} ]; then
# try the "main" country code if any
main_country=
while read line; do
if [ "${line%%[[:space:]]*}" = $langcode ]; then
main_country=${line##*[[:space:]]}
if [ $lang != ${lang#*@} ]; then
main_country=$main_country@${lang#*@}
fi
break
fi
done < $langtoolsdir/main-countries
if [ -n "$main_country" ]; then
for loc in $locales; do
if [ $main_country = $loc ]; then
locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
break
fi
done
fi
# try out fitting locale with any country code
if [ -z "$locale_name" -a $langcode != 'zh' ]; then
for loc in $locales; do
if [ "${loc%%[_@]*}" = $langcode ]; then
locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
break
fi
done
fi
fi
echo $locale_name
|