summaryrefslogtreecommitdiff
path: root/core/glibc/locale-gen
blob: 51191f8109238a328df859cca65c96b13a6443f1 (plain)
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
#!/bin/sh

set -e

LOCALEGEN=/etc/locale.gen
LOCALES=/usr/share/i18n/locales
unset POSIXLY_CORRECT

[ -s "$LOCALEGEN" ] || exit 0

# Remove all old locale dir and locale-archive before generating new
# locale data.
rm -rf /usr/lib/locale/*

umask 022

gen() {
	local locale=$1
	local charset=$2
	local input=

	if [ -z "$locale" ] || [ -z "$charset" ]; then
		echo "error: Bad entry '$locale $charset'"
		return
	fi

	printf '  %s.%s\n' "$(echo "$locale" | sed 's/\([^.\@]*\).*/\1/')" "$charset"

	if [ -f "$LOCALES/$locale" ]; then
		input=$locale
	else
		input=$(echo $locale | sed 's/\([^.]*\)[^@]*\(.*\)/\1\2/')
	fi

	localedef -i "$input" -c -f "$charset" -A /usr/share/locale/locale.alias "$locale"
}

maxjobs=$(grep -c processor /proc/cpuinfo 2>/dev/null || echo 1)
echo "Generating locales..."
while read locale charset; do \
	case $locale in
		\#*|'')
			continue
			;;
	esac
	gen "$locale" "$charset" &

	# keep no more than $maxjobs jobs in flight
	while [ $(jobs | wc -l) -ge $maxjobs ]; do
		sleep 0.25
		jobs >/dev/null
	done
done < $LOCALEGEN
wait

echo "Generation complete."