Browse Source

Use $NLSPATH to install locales

signals
Gavin Howard 3 years ago
parent
commit
aea5bdb808
Signed by untrusted user who does not match committer: gavin
GPG Key ID: C08038BDF280D33E
  1. 89
      functions.sh
  2. 32
      locale_install.sh

89
functions.sh

@ -29,12 +29,27 @@
readlink() {
local exe="$1"
local f="$1"
shift
L=$(ls -dl "$exe")
local arrow="-> "
local d=$(dirname "$f")
printf "${L#*-> }"
local lsout=""
local link=""
lsout=$(ls -dl "$f")
link=$(printf '%s' "${lsout#*$arrow}")
while [ -z "${lsout##*$arrow*}" ]; do
cd "$d"
f="$link"
d=$(dirname "$f")
lsout=$(ls -dl "$f")
link=$(printf '%s' "${lsout#*$arrow}")
done
printf '%s' "${f##*$d/}"
}
removeext() {
@ -125,15 +140,71 @@ checktest()
substring_replace() {
if [ "$#" -ne 3 ]; then
err_exit "Invalid number of args to $0"
fi
local str="$1"
shift
local needle="$1"
shift
str="$1"
needle="$2"
replacement="$3"
local replacement="$1"
shift
result=$(printf '%s' "$str" | sed -e "s!$needle!$replacement!g")
printf '%s\n' "$result"
}
gen_nlspath() {
local nlspath="$1"
shift
local locale="$1"
shift
local execname="$1"
shift
local char="@"
local modifier="${locale#*$char}"
local tmplocale="${locale%%$char*}"
char="."
local charset="${tmplocale#*$char}"
tmplocale="${tmplocale%%$char*}"
if [ "$charset" = "$tmplocale" ]; then
charset=""
fi
char="_"
local territory="${tmplocale#*$char}"
local language="${tmplocale%%$char*}"
if [ "$territory" = "$tmplocale" ]; then
territory=""
fi
if [ "$language" = "$tmplocale" ]; then
language=""
fi
local needles="%%:%L:%N:%l:%t:%c"
needles=$(printf '%s' "$needles" | tr ':' '\n')
for i in $needles; do
nlspath=$(substring_replace "$nlspath" "$i" "\n$i\n")
done
nlspath=$(substring_replace "$nlspath" "%%" "%")
nlspath=$(substring_replace "$nlspath" "%L" "$locale")
nlspath=$(substring_replace "$nlspath" "%N" "$execname")
nlspath=$(substring_replace "$nlspath" "%l" "$language")
nlspath=$(substring_replace "$nlspath" "%t" "$territory")
nlspath=$(substring_replace "$nlspath" "%c" "$charset")
nlspath=$(printf '%s' "$nlspath" | tr -d '\n')
printf '%s\n' "$nlspath"
}

32
locale_install.sh

@ -28,7 +28,7 @@
#
usage() {
printf "usage: %s install_dir main_exec\n" "$0" 1>&2
printf "usage: %s NLSPATH main_exec\n" "$0" 1>&2
exit 1
}
@ -41,7 +41,7 @@ INSTALL="$scriptdir/safe-install.sh"
test "$#" -ge 2 || usage
install_dir="$1"
nlspath="$1"
shift
main_exec="$1"
@ -49,24 +49,30 @@ shift
locales_dir="$scriptdir/locales"
locales=$(locale -a)
for file in $locales_dir/*.msg; do
base=$(basename "$file")
name=$(removeext "$base")
d="$install_dir/$name/LC_MESSAGES"
loc="$install_dir/$name/LC_MESSAGES/$main_exec.cat"
locale=$(removeext "$base")
loc=$(gen_nlspath "$nlspath" "$locale" "$main_exec")
if [ ! -z "${locales##*$locale*}" ]; then
printf 'The following locale is not supported: %s\nContinuing...\n' "$locale"
continue
fi
mkdir -p "$d"
mkdir -p $(dirname "$loc")
if [ -L "$file" ]; then
link=$(readlink "$file")
linkname=$(removeext "$link")
"$INSTALL" -Dlm 755 "../../$linkname/LC_MESSAGES/$main_exec.cat" "$loc"
else
err_msgs=$(gencat "$loc" "$file" 2>&1)
if [ "$err_msgs" != "" ]; then
printf '\nWarning: gencat produced the following errors:\n\n%s\n\n' "$err_msgs"
fi
d=$(dirname "$file")
file="$d/$link"
fi
err_msgs=$(gencat "$loc" "$file" 2>&1)
if [ "$err_msgs" != "" ]; then
printf '\nWarning: gencat produced the following errors:\n\n%s\n\n' "$err_msgs"
fi
done

Loading…
Cancel
Save