[pacman-dev] [PATCH] Gettext support in repo-add

Giovanni Scafora linuxmania at gmail.com
Mon Apr 2 13:17:20 EDT 2007


Add gettext support to repo-add.

Signed-off-by: Giovanni Scafora <linuxmania at gmail.com>

diff --git a/scripts/repo-add b/scripts/repo-add
index 8b81c34..200f875 100755
--- a/scripts/repo-add
+++ b/scripts/repo-add
@@ -19,6 +19,14 @@
 #   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 #   USA.

+# gettext initialization"
+source gettext.sh
+
+TEXTDOMAIN=repo-add
+export TEXTDOMAIN
+TEXTDOMAINDIR='@localedir@'
+export TEXTDOMAINDIR
+
 myver='3.0.0'

 FORCE=0
@@ -27,19 +35,19 @@ TMP_DIR=""

 # print usage instructions
 usage() {
-	echo "repo-add $myver"
+	echo "$(gettext "repo-add %s")" $myver
 	echo
-	echo "usage: repo-add <path-to-db> [--force] <package> ..."
+	echo "$(gettext "usage: repo-add <path-to-db> [--force] <package> ...")"
 	echo
-	echo "repo-add will update a package database by reading a package file."
-	echo "Multiple packages to add can be specified on the command line."
+	echo "$(gettext "repo-add will update a package database by reading
a package file.")"
+	echo "$(gettext "Multiple packages to add can be specified on the
command line.")"
 	echo
-	echo "The --force flag will add a 'force' entry to the sync database, which"
-	echo "tells pacman to skip its internal version number checking and update"
-	echo "the package regardless."
+	echo "$(gettext "The --force flag will add a 'force' entry to the
sync database, which")"
+	echo "$(gettext "tells pacman to skip its internal version number
checking and update")"
+	echo "$(gettext "the package regardless.")"
 	echo
-	echo "Example:"
-	echo "  repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz"
+	echo "$(gettext "Example:")"
+	echo "$(gettext "  repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
 	echo
 }

@@ -127,14 +135,14 @@ db_write_entry()

 	# ensure $pkgname and $pkgver variables were found
 	if [ -z "$pkgname" -o -z "$pkgver" ]; then
-		echo "   error: invalid package file"
+		echo "$(gettext "   error: invalid package file")"
 		return 1
 	fi

 	# remove any other package in the DB with same name
 	for existing in *; do
 		if [ "${existing%-*-*}" = "$pkgname" ]; then
-			echo ":: removing existing package '$existing'"
+			echo "$(gettext ":: removing existing package '%s'")" $existing
 			rm -rf $existing
 		fi
 	done
@@ -144,7 +152,7 @@ db_write_entry()
 	cd "$pkgname-$pkgver"

 	# create desc entry
-	echo ":: creating 'desc' db entry"
+	echo "$(gettext ":: creating 'desc' db entry")"
 	echo -e "%FILENAME%\n$(basename $1)\n" >> desc
 	echo -e "%NAME%\n$pkgname\n" >>desc
 	echo -e "%VERSION%\n$pkgver\n" >>desc
@@ -162,7 +170,7 @@ db_write_entry()
 	# compute checksums
 	for chk in ${DB_CHECKSUMS[@]}; do
 		name="$(checksum_name $chk)"
-		echo ":: computing $name checksums"
+		echo "$(gettext ":: computing %s checksums")" $name
 		if [ -n "$name" ]; then
 			echo -e "%$name%\n$(get_checksum $chk $pkgfile)\n" >>desc
 		fi
@@ -225,7 +233,7 @@ fi
 if [ -r /etc/makepkg.conf ]; then
 	source /etc/makepkg.conf
 else
-	echo "ERROR: /etc/makepkg.conf not found. Can not continue." >&2
+	echo "$(gettext "ERROR: /etc/makepkg.conf not found. Can not continue.")" >&2
 	exit 1 # $E_CONFIG_ERROR # TODO: error codes
 fi

@@ -236,7 +244,7 @@ fi
 # main routine
 if [ $# -gt 1 ]; then
 	gstmpdir=$(mktemp -d /tmp/gensync.XXXXXXXXXX) || (\
-	echo "cannot create temp directory for database building"; \
+	echo "$(gettext "cannot create temp directory for database building")"; \
 	exit 1)

 	success=0
@@ -247,18 +255,18 @@ if [ $# -gt 1 ]; then
 		elif [ -z "$REPO_DB_FILE" ]; then
 			REPO_DB_FILE="$(readlink -f $arg)"
 			if ! test_repo_db_file; then
-				echo "error: repository file '$REPO_DB_FILE' is not a proper pacman db"
+				echo "$(gettext "error: repository file '%s' is not a proper
pacman db")" $REPO_DB_FILE
 				exit 1
 			elif [ -f "$REPO_DB_FILE" ]; then
-				echo ":: extracting database to a temporary location"
+				echo "$(gettext ":: extracting database to a temporary location")"
 				tar xf "$REPO_DB_FILE" -C "$gstmpdir"
 			fi
 		else
 			if [ -f "$arg" ]; then
 				if ! tar tf "$arg" .PKGINFO 2>&1 >/dev/null; then
-					echo "error: '$arg' is not a package file, skipping"
+					echo "$(gettext "error: '%s' is not a package file, skipping")" $arg
 				else
-					echo ":: adding package '$arg'"
+					echo "$(gettext ":: adding package '%s'")" $arg

 					this_dir="$(pwd)"
 					if db_write_entry "$arg"; then
@@ -267,14 +275,14 @@ if [ $# -gt 1 ]; then
 					cd $this_dir
 				fi
 			else
-				echo "error: package '$arg' not found"
+				echo "$(gettext "error: package '%s' not found")" $arg
 			fi
 		fi
 	done

 	# if all operations were a success, rezip database
 	if [ "$success" = "1" ]; then
-		echo ":: creating updated database file ${REPO_DB_FILE}"
+		echo "$(gettext ":: creating updated database file %s")" ${REPO_DB_FILE}
 		cd $gstmpdir
 		if [ -n "$(ls)" ]; then
 			[ -f "${REPO_DB_FILE}.old" ] && rm "${REPO_DB_FILE}.old"
@@ -282,12 +290,12 @@ if [ $# -gt 1 ]; then
 			case "$DB_COMPRESSION" in
 				gz) tar c * | gzip -9 >$REPO_DB_FILE ;;
 				bz2) tar c * | bzip2 -9 >$REPO_DB_FILE ;;
-				*) echo "warning: no compression set"
+				*) echo "$(gettext "warning: no compression set")"
 				tar c * >$REPO_DB_FILE;;
 			esac
 		fi
 	else
-		echo ":: no packages modified, nothing to do"
+		echo "$(gettext ":: no packages modified, nothing to do")"
 	fi
 fi

-- 
1.5.0.6



-- 
Giovanni Scafora
Arch Linux Trusted User (voidnull)
http://www.archlinux.org
linuxmania at gmail.com




More information about the pacman-dev mailing list