使い方:
(バイナリプログラムの場合)
- たとえば /usr/bin/C と /usr/bin/ja ディレクトリを作ります。
- オリジナル(英文)を /usr/bin/C/gexec に、日本語化されたものを /usr/bin/ja/gexec に置きます。
- リンクを作ります。ln -s /usr/bin/L10nSwitcher /usr/bin/gexec
(シェルスクリプトの場合)
たとえばスクリプト /usr/bin/xsaneshell の場合、日本語化されたものを /usr/bin/ja/xsaneshell に置き、
オリジナル /usr/bin/xsaneshell の冒頭に次のコードを挿入します。
[ -f /usr/bin/L10nSwitcher ] && source /usr/bin/L10nSwitcher
これで /usr/bin/xsaneshell を呼ぶと 環境変数LANGが ja..のときのみ /usr/bin/ja/xsaneshell に制御が移ります。
L10nSwitcherのコード:
(10月7日 パラメータ受け渡し部分を修正)
コード: 全て選択
#!/bin/sh
# 7sep09 L10n switcher by shinobar
# 7oct09 way to pass parameters
usage() {
echo "'L10nSwitcher' sholud not be run directory.
It is a kind of wrapper to seek localized program
from the directory under the excuting directory.
Ex.1:
Make 2 directories, /usr/bin/C and /usr/bin/ja.
Move the original program, for example, /usr/bin/gexec
to /usr/bin/C/gexec.
Japanized 'gexec' at /usr/bin/ja/gexec.
Make symlink of /usr/bin/L10nSwitcher at /usr/bin/gexec.
Such as like:
# ln -sf /usr/bin/L10nSwitcher /usr/bin/gexec
Ex.2:
If the program is shell script, for exsample,
/usr/bin/xsaneshell:
Japanized 'xsaneshell' at /usr/bin/ja/xsaneshell.
Insert next line at the top of the original 'xsaneshell'.
[ -f /usr/bin/L10nSwitcher ] && source /usr/bin/L10nSwitcher
"
}
error () {
usage
exit 1
}
MYNAME=$(basename "$0")
[ "$MYNAME" = 'L10nSwitcher' ] && error
EXECDIR="$(dirname "$0")"
[ "$EXECDIR" = "." -a ! -x "$MYNAME" ] && EXECDIR="$(dirname $(which $MYNAME))"
# set locale
for lng in C $(echo $LANGUAGE|cut -d':' -f1) $LC_ALL $LANG;do :;done # ex. ja_JP.UTF-8
# search locale file
lng1=$(echo $lng|cut -d'.' -f1) # ex. ja_JP
lng2=$(echo $lng|cut -d'_' -f1) # ex. ja
for D in $lng $lng1 $lng2 C en
do
export L10n_APPDIR="$EXECDIR/$D"
F="$L10n_APPDIR/$MYNAME" #;echo "$F"
if [ -x "$F" ] ;then
PARAM=""
for I in $(seq 1 1 $#);do PARAM="$PARAM \"\$$I\"";done
eval exec \"$F\" $PARAM
#exec "$F" $@
fi
done
echo "Excutable $MYNAME not found." >&2