Debian Codegraph @

debian/local/usr_sbin/locale-gen

raw symbols SCIP
1 #!/bin/sh
2
3 set -e
4
5 LOCALEGEN=/etc/locale.gen
6 LOCALES=/usr/share/i18n/locales
7 USER_LOCALES=/usr/local/share/i18n/locales
8
9
10 [ -s "$LOCALEGEN" ] || exit 0
11
12 [ "$1" = '--keep-existing' ] && KEEP=1 || KEEP=0
13
14 # Remove old locale-archive before generating new locale data
15 [ "$KEEP" -eq 0 ] && rm -rf /usr/lib/locale/locale-archive || :
16
17 umask 022
18
19 is_entry_ok() {
20 if [ -z "$locale" ] || [ -z "$charset" ]; then
21 echo "error: Bad entry '$locale $charset'"
22 return 1
23 fi
24 }
25
26 if [ -z "${I18NPATH:-}" ]; then
27 if [ -d "${USER_LOCALES}" ]; then
28 I18NPATH="${USER_LOCALES%%/locales*}/"
29 fi
30 fi
31
32 echo "Generating locales (this might take a while)..."
33 while read -r locale charset; do
34 if [ -z "$locale" ] || [ "${locale#\#}" != "$locale" ]; then continue; fi
35 is_entry_ok || continue
36
37 if [ "$KEEP" -eq 1 ] && PERL_BADLANG=0 perl -MPOSIX -e 'exit 1 unless setlocale(LC_ALL, $ARGV[0])' "$locale"; then continue; fi
38
39 locale_base="${locale%%.*}"
40 locale_base="${locale_base%%@*}"
41 locale_at="${locale#*@}"
42 [ "$locale_at" = "$locale" ] && locale_at= || locale_at="@$locale_at"
43 printf " %s.%s%s..." "$locale_base" "$charset" "$locale_at"
44
45 if [ -e "$USER_LOCALES/$locale" ]; then
46 input="$USER_LOCALES/$locale"
47 elif [ -e "$LOCALES/$locale" ]; then
48 input="$locale"
49 else
50 input="$locale_base$locale_at"
51 if [ -e "$USER_LOCALES/$input" ]; then
52 input="$USER_LOCALES/$input"
53 fi
54 fi
55 I18NPATH="${I18NPATH}" localedef -i "$input" -c -f "$charset" "$locale" || :
56 echo " done"
57 done < "$LOCALEGEN"
58 echo "Generation complete."