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