Make .desktop files available for translation
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 17 Sep 2008 20:47:20 +0000 (20:47 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 17 Sep 2008 20:47:20 +0000 (20:47 +0000)
Most of the patch is by Jordà Polo, I did the build integration.

git-svn-id: https://s.snth.net/svn/neverball/trunk@2524 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
dist/neverball.desktop [deleted file]
dist/neverball.desktop.in [new file with mode: 0644]
dist/neverputt.desktop [deleted file]
dist/neverputt.desktop.in [new file with mode: 0644]
po/fr.po
scripts/extractpo.sh
scripts/translate-desktop.sh [new file with mode: 0644]

index 934e785..25e1eed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -227,6 +227,8 @@ MAPC_DEPS := $(MAPC_OBJS:.o=.d)
 MAPS := $(shell find data -name "*.map" \! -name "*.autosave.map")
 SOLS := $(MAPS:%.map=%.sol)
 
+DESKTOPS := $(basename $(wildcard dist/*.desktop.in))
+
 #------------------------------------------------------------------------------
 
 %.o : %.c
@@ -236,9 +238,12 @@ SOLS := $(MAPS:%.map=%.sol)
 %.sol : %.map $(MAPC_TARG)
        $(MAPC) $< data
 
+%.desktop : %.desktop.in
+       sh scripts/translate-desktop.sh < $< > $@
+
 #------------------------------------------------------------------------------
 
-all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales
+all : $(BALL_TARG) $(PUTT_TARG) $(MAPC_TARG) sols locales desktops
 
 $(BALL_TARG) : $(BALL_OBJS)
        $(CC) $(ALL_CFLAGS) -o $(BALL_TARG) $(BALL_OBJS) $(LDFLAGS) $(ALL_LIBS)
@@ -262,6 +267,8 @@ ifneq ($(ENABLE_NLS),0)
        $(MAKE) -C po
 endif
 
+desktops : $(DESKTOPS)
+
 clean-src :
        $(RM) $(BALL_TARG) $(BALL_OBJS) $(BALL_DEPS)
        $(RM) $(PUTT_TARG) $(PUTT_OBJS) $(PUTT_DEPS)
@@ -269,6 +276,7 @@ clean-src :
 
 clean : clean-src
        $(RM) $(SOLS)
+       $(RM) $(DESKTOPS)
        $(MAKE) -C po clean
 
 test : all
diff --git a/dist/neverball.desktop b/dist/neverball.desktop
deleted file mode 100644 (file)
index 8a25f44..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[Desktop Entry]
-Version=1.0
-Type=Application
-Name=Neverball
-Comment=A 3D arcade game with a ball
-Comment[fr]=Un jeu d'arcade 3D avec une balle
-Icon=neverball
-Exec=neverball
-Terminal=false
-Categories=Game;ArcadeGame;
diff --git a/dist/neverball.desktop.in b/dist/neverball.desktop.in
new file mode 100644 (file)
index 0000000..dfd7917
--- /dev/null
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+Name=Neverball
+Comment=A 3D arcade game with a ball
+Icon=neverball
+Exec=neverball
+Terminal=false
+Categories=Game;ArcadeGame;
diff --git a/dist/neverputt.desktop b/dist/neverputt.desktop
deleted file mode 100644 (file)
index 8472b0c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[Desktop Entry]
-Version=1.0
-Type=Application
-Name=Neverputt
-Comment=A 3D mini golf game
-Comment[fr]=Un jeu de minigolf en 3D
-Icon=neverputt
-Exec=neverputt
-Terminal=false
-Categories=Game;ArcadeGame;
diff --git a/dist/neverputt.desktop.in b/dist/neverputt.desktop.in
new file mode 100644 (file)
index 0000000..688e929
--- /dev/null
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+Name=Neverputt
+Comment=A 3D mini golf game
+Icon=neverputt
+Exec=neverputt
+Terminal=false
+Categories=Game;ArcadeGame;
index 573752a..eb6e591 100644 (file)
--- a/po/fr.po
+++ b/po/fr.po
@@ -1712,6 +1712,12 @@ msgstr "mtrl/words-fr"
 msgid "item/coin/coin"
 msgstr "item/coin/euro_coin"
 
+msgid "A 3D arcade game with a ball"
+msgstr "Un jeu d'arcade 3D avec une balle"
+
+msgid "A 3D mini golf game"
+msgstr "Un jeu de minigolf en 3D"
+
 #~ msgid "Mode"
 #~ msgstr "Mode"
 #~ msgid "Follow the yellow lick road..."
index 72f828a..496f86a 100644 (file)
@@ -1,5 +1,6 @@
 #!/bin/sh
-# This script extracts translatable messages from maps and sets.
+# This script extracts translatable messages from maps, sets and
+# desktop files.
 # Copyright (C) 2006 Jean Privat
 #
 # Part of the Neverball project
@@ -26,15 +27,27 @@ DATA="data"
 SETS="$DATA/sets.txt"
 COURSES="$DATA/courses.txt"
 
+print_msg() {
+    string=$1
+    file=$2
+    comment=$3
+
+    echo
+    if [ "$comment" != "" ]; then
+        echo "#. $comment"
+    fi
+    echo "#: $file"
+    echo "msgid \"$string\""
+    echo "msgstr \"\""
+}
+
 for i in $(cat "$SETS"); do
     i="$DATA/$i"
 
     # Only translate the two first lines
     head -n 2 $i | while read -r d; do
-        echo
-        echo "#: $i"
-        echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
-        echo "msgstr \"\""
+        msg=$(echo "$d" | sed 's/\\/\\\\/g')
+        print_msg "$msg" "$i"
     done
 done
 
@@ -42,20 +55,23 @@ done
 echo | cat "$COURSES" - | while read -r d; do
     # Heuristic: description is non empty line without .txt inside
     if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
-        echo
-        echo "#: $COURSES"
-        echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
-        echo "msgstr \"\""
+        msg=$(echo "$d" | sed 's/\\/\\\\/g')
+        print_msg "$msg" "$COURSES"
     fi
 done
 
 for i in $(find $DATA -name "*.map" | sort); do
     # Only translatable string is "message"
     grep -E "^\"message\"" "$i" | while read -r a b; do
-        echo
-        echo "#: $i"
-        echo "msgid $(echo "$b" | sed 's/\\/\\\\/g')"
-        echo "msgstr \"\""
+        msg=$(echo "$b" | sed 's/\\/\\\\/g; s/^"\(.*\)"$/\1/')
+        print_msg "$msg" "$i"
     done
 done
 
+for i in dist/*.desktop.in; do
+    msg=$(grep '^Comment=' $i | sed 's/^Comment=//')
+    if [ "$msg" != "" ]; then
+        print_msg "$msg" "$i" "Desktop entry comment"
+    fi
+done
+
diff --git a/scripts/translate-desktop.sh b/scripts/translate-desktop.sh
new file mode 100644 (file)
index 0000000..8ea9335
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+# This script reads a .desktop file from stdin and prints the same file, with
+# up-to-date translations, to stdout.
+
+while read line; do
+    # Remove translations
+    if echo $line | grep '^.*\[.*\]=' > /dev/null; then
+        continue
+    fi
+
+    echo $line
+
+    # Generate translations if current line is translatable
+    if echo $line | grep '^Comment=' > /dev/null; then
+        msgid=`echo $line | sed 's/^Comment=//'`
+        for i in po/*.po; do
+            lang=`basename $i | sed 's/\.po//'`
+            msgstr=`msgattrib --translated --no-obsolete --no-fuzzy $i \
+                    | msggrep --no-location --no-wrap --msgid -F -e "$msgid" \
+                    | tail -n 1 | sed 's/^msgstr "\(.*\)"$/\1/'`
+            if [ "$msgstr" != "" ]; then
+                echo "Comment[$lang]=$msgstr"
+            fi
+        done
+    fi
+done