L10nSwitcher

4.X系の開発

モデレータ: 暇人, YoN, nyu

返信する
アバター
シノバー
記事: 3139
登録日時: 09/03/21(土) 00:05
連絡する:

L10nSwitcher

投稿記事 by シノバー »

424jaに同梱のローカライズドプログラム切替器です。- /usr/bin/L10nSwitcher

使い方:
(バイナリプログラムの場合)
  1. たとえば /usr/bin/C と /usr/bin/ja ディレクトリを作ります。
  2. オリジナル(英文)を /usr/bin/C/gexec に、日本語化されたものを /usr/bin/ja/gexec に置きます。
  3. リンクを作ります。ln -s /usr/bin/L10nSwitcher /usr/bin/gexec
これで /usr/bin/gexec を呼ぶと、環境変数LANGの値によって /usr/bin/ja/gexec あるいは /usr/bin/C/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
The bar master, Shino's Bar
http://shinobar.net/
返信する