Check-in [47509d2301]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

SHA1 Hash:47509d2301934fbf5b1639a3a2075ce844ff35b4
Date: 2012-02-06 07:56:41
User: BarryK
Comment:MoManager now manages .desktop menu files

Tags And Properties
Changes

Changes to woof-code/rootfs-skeleton/usr/sbin/momanager

@@ -2,11 +2,12 @@
 #(c) Barry Kauler Feb 2012 bkhome.org
 #licence GPL3 refer /usr/share/doc/legal
 #the intention of this script is to manage non-english translations of files.
 #this is to include shell scripts, xml, .desktop and menu files.
 #translation will only be for the current language, and UTF-8 must be enabled.
-#120205 first release.
+#120205 first release, handle gettext'ed scripts.
+#120206 added internationalization management of menu.
 
 PARAM1=""
 [ $1 ] && PARAM1="$1"
 
 ORIGLANG=$LANG
@@ -74,14 +75,14 @@
 fi
 
 yaf-splash -close never -bg orange -text "Please wait, scanning files..." &
 yPID=$!
 
+#####SCRIPTS#######
 #find all gettext'ed scripts...
 #GETTEXTSCRIPTS="`find ${PATHPREFIX}/bin ${PATHPREFIX}/sbin ${PATHPREFIX}/usr/bin ${PATHPREFIX}/usr/sbin ${PATHPREFIX}/usr/X11R7/bin ${PATHPREFIX}/usr/local ${PATHPREFIX}/etc/rc.d -maxdepth 4 -type f -executable | xargs -I INPUTFILE grep --files-with-matches '^export TEXTDOMAIN=' INPUTFILE | sed -e 's% %SPACECHAR%g' -e "$ppPTN" | sort | tr '\n' ' '`"
 GETTEXTSCRIPTS="`find /bin /sbin /usr/bin /usr/sbin /usr/X11R7/bin /usr/local /etc/rc.d /root/my-applications/bin -maxdepth 4 -type f -executable | xargs -I INPUTFILE grep --files-with-matches '^export TEXTDOMAIN=' INPUTFILE | sed -e 's% %SPACECHAR%g' | sort | tr '\n' ' '`"
-
 
 #find all matching .mo files...
 YESCNT=0; NOCNT=0; YESMO_XML=""; NOMO_XML=""
 for AGTS in $GETTEXTSCRIPTS
 do
@@ -92,11 +93,11 @@
  BASExAGTS="`basename "$xAGTS"`"
  xPTN=" ${BASExAGTS}$"
  PATHxAGTS="`dirname "$xAGTS"`"
  xxPTN="^${PATHxAGTS}$"
  zPTN="^${xAGTS}$"
- aPKGNAME="`grep "$xPTN" /root/.packages/builtin_files/* | head -n 1 | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | rev`" #test pkg used in Woof build.
+ aPKGNAME="`grep "$xPTN" /root/.packages/builtin_files/* | head -n 1 | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | rev`" #test if pkg used in Woof build.
  if [ "$aPKGNAME" ];then #confirm full path.
   CONFIRM="`cat /root/.packages/builtin_files/${aPKGNAME} | sed -e 's%^ %/%' | tr -d '\n' | grep "$xAGTS"`"
   [ ! "$CONFIRM" ] && aPKGNAME=""
  fi
  [ ! "$aPKGNAME" ] && aPKGNAME="`grep "$zPTN" /root/.packages/*.files 2>/dev/null | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | rev | sed -e 's%\.files$%%'`" #test if user-installed pkg.
@@ -127,19 +128,58 @@
   NOMO_XML="${NOMO_XML}
 <item>${xAGTS} (${TEXTDOMAINVALUE} ${aPKGNAME})</item>"
  fi
 done
 if [ "$YESMO_XML" ];then
- YESMO_XML="<combobox width-request=\"370\"><variable>YESMO_COMBO</variable>${YESMO_XML}</combobox>"
+ YESMO_XML="<combobox width-request=\"310\"><variable>YESMO_COMBO</variable>${YESMO_XML}</combobox>"
 else
  YESMO_XML="<text><label>nothing</label></text>"
 fi
 if [ "$NOMO_XML" ];then
- NOMO_XML="<combobox width-request=\"370\"><variable>NOMO_COMBO</variable>${NOMO_XML}</combobox>"
+ NOMO_XML="<combobox width-request=\"330\"><variable>NOMO_COMBO</variable>${NOMO_XML}</combobox>"
+else
+ NOMO_XML="<text><label>nothing</label></text>"
+fi
+
+#######MENU#######
+#find out which .desktop files have [lang] entries already, create two lists...
+YESDESK_XML=""; NODESK_XML=""
+dPTN="\\[${ORIGLANG1}\\]"
+for ADESKTOP in `find /usr/share/applications -mindepth 1 -maxdepth 1 -type f -name '*.desktop' | grep -v ' ' | sort | tr '\n' ' '`
+do
+ [ "`grep '^Icon' $ADESKTOP`" = "" ] && continue #some dummy .desktop files used by xfce, ignore them.
+ ADESKNAME="`basename $ADESKTOP`"
+
+ #find out what package it is from...
+ xPTN=" ${ADESKNAME}$"
+ zPTN="^${ADESKTOP}$"
+ aPKGNAME="`grep "$xPTN" /root/.packages/builtin_files/* | head -n 1 | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | rev`" #test if pkg used in Woof build.
+ [ ! "$aPKGNAME" ] && aPKGNAME="`grep "$zPTN" /root/.packages/*.files 2>/dev/null | cut -f 1 -d ':' | rev | cut -f 1 -d '/' | rev | sed -e 's%\.files$%%'`" #test if user-installed pkg.
+ #...return nothing if in Woof
+ [ ! "$aPKGNAME" ] && [ -f "${PATHPREFIX}${ADESKTOP}" ] && aPKGNAME="WOOF" #file is in Woof.
+ [ ! "$aPKGNAME" ] && aPKGNAME="UNKNOWN"
+
+ if [ "`grep "$dPTN" $ADESKTOP`" != "" ];then
+  YESDESK_XML="${YESDESK_XML}
+<item>${ADESKNAME} (${aPKGNAME})</item>"
+ else
+  NODESK_XML="${NODESK_XML}
+<item>${ADESKNAME} (${aPKGNAME})</item>"
+ fi
+done
+if [ "$YESDESK_XML" ];then
+ YESDESK_XML="<combobox width-request=\"310\"><variable>YESDESK_COMBO</variable>${YESDESK_XML}</combobox>"
+else
+ YESDESK_XML="<text><label>nothing</label></text>"
+fi
+if [ "$NODESK_XML" ];then
+ NODESK_XML="<combobox width-request=\"330\"><variable>NODESK_COMBO</variable>${NODESK_XML}</combobox>"
 else
- YESMO_XML="<text><label>nothing</label></text>"
+ NODESK_XML="<text><label>nothing</label></text>"
 fi
+
+
 
 export MM2_DLG="<window title=\"MoManager: Puppy files\" window_position=\"1\" resizable=\"false\">
  <vbox>
 
   <frame Scripts>
@@ -149,26 +189,41 @@
   </hbox>
   <hbox>
    <vbox>
     <frame Scripts that have a mo file>
      <text><label>A translation file in your language (${ORIGLANG12}) will be at /usr/share/locale/${ORIGLANG12}/LC_MESSAGES/ or /usr/share/locale/${ORIGLANG1}/LC_MESSAGES/. You may select one of the scripts, then click the 'Edit' button to update it...</label></text>
-     ${YESMO_XML}
-     <hbox><button><label>Edit</label><action>EXIT:edit_mo</action></button></hbox>
+
+     <hbox>${YESMO_XML}<button><label>Edit</label><action>EXIT:edit_mo</action></button></hbox>
     </frame>
    </vbox>
    <vbox>
     <frame Scripts that do not have a mo file>
      <text><label>These scripts do not have a translation file for your language. You may select one of the scripts, then click the 'Create' button to create a translation...</label></text>
-     ${NOMO_XML}
-     <hbox><button><label>Create</label><action>EXIT:create_mo</action></button></hbox>
+
+     <hbox>${NOMO_XML}<button><label>Create</label><action>EXIT:create_mo</action></button></hbox>
     </frame>
    </vbox>
   </hbox>
   </frame>
 
   <frame Menu>
-   <text><label>coming soon</label></text>
+   <hbox>
+    <text use-markup=\"true\"><label>\"Menu entries are defined by files in folder /usr/share/applications. A line <b>Name[${ORIGLANG1}]=</b> is required with text that will appear in the menu. You need to edit the string to be a suitable translation from the English menu string...\"</label></text>
+    <text><label>The extra information in brackets is the name of the package that the file belongs to. 'WOOF' means that the file is in Woof.</label></text>
+   </hbox>
+   <hbox>
+    <vbox>
+     <frame Menu files with a ${ORIGLANG1} translation>
+      <hbox>${YESDESK_XML}<button><label>Edit</label><action>EXIT:edit_desk</action></button></hbox>
+     </frame>
+    </vbox>
+    <vbox>
+     <frame Menu files without a ${ORIGLANG1} translation>
+     <hbox>${NODESK_XML}<button><label>Create</label><action>EXIT:create_desk</action></button></hbox>
+     </frame>
+    </vbox>
+   </hbox>
   </frame>
 
   <frame ROX-Filer>
    <text><label>coming soon</label></text>
   </frame>
@@ -228,10 +283,11 @@
    cp -f /tmp/momanager/${ATEXTDOMAIN}.mo "${AMOSPEC}"
    cd /tmp/momanager
    rm -f ${ATEXTDOMAIN}.mo.gz 2>/dev/null
    gzip ${ATEXTDOMAIN}.mo
    ASTAT="`stat --format=%y "$ASCRIPT" | cut -f 1 -d ' ' | tr -d '-' `" #so can check against file version in latest Woof.
+   [ -f ${PATHPREFIX}${ASCRIPT} ] && ASTAT="`stat --format=%y "${PATHPREFIX}$ASCRIPT" | cut -f 1 -d ' ' | tr -d '-' `" #get orig modify date.
    mv -f /tmp/momanager/${ATEXTDOMAIN}.mo.gz /root/${ASTAT}_${ADATE}_${ATRANSLANG}_${ATEXTDOMAIN}.mo.gz
    case $APKGNAME in
     WOOF)
      DONEMSG="Ok, the new .mo file is in place, and if you wish you may run the script to test it. The script ${ANAME} is part of Woof, so if the translation works, please email it to Barry Kauler so that it may be included in Woof for all future Puppy builds. File \Zb/root/${ASTAT}_${ADATE}_${ATRANSLANG}_${ATEXTDOMAIN}.mo.gz\ZB has been created, that you can email to Barry at: \Zbbkauler@gmail.com\ZB -- thanks, that will be very helpful for internationalization of Puppy!"
     ;;
@@ -295,10 +351,11 @@
    cp -f /tmp/momanager/${ATEXTDOMAIN}.mo "${AMOSPEC}"
    cd /tmp/momanager
    rm -f ${ATEXTDOMAIN}.mo.gz 2>/dev/null
    gzip ${ATEXTDOMAIN}.mo
    ASTAT="`stat --format=%y "$ASCRIPT" | cut -f 1 -d ' ' | tr -d '-' `" #so can check against file version in latest Woof.
+   [ -f ${PATHPREFIX}${ASCRIPT} ] && ASTAT="`stat --format=%y "${PATHPREFIX}$ASCRIPT" | cut -f 1 -d ' ' | tr -d '-' `" #get orig modify date.
    mv -f /tmp/momanager/${ATEXTDOMAIN}.mo.gz /root/${ASTAT}_${ADATE}_${ATRANSLANG}_${ATEXTDOMAIN}.mo.gz
    case $APKGNAME in
     WOOF)
      DONEMSG="Ok, the new .mo file is in place, and if you wish you may run the script to test it. The script ${ANAME} is part of Woof, so if the translation works, please email it to Barry Kauler so that it may be included in Woof for all future Puppy builds. File \Zb/root/${ASTAT}_${ADATE}_${ATRANSLANG}_${ATEXTDOMAIN}.mo.gz\ZB has been created, that you can email to Barry at: \Zbbkauler@gmail.com\ZB -- thanks, that will be very helpful for internationalization of Puppy!"
     ;;
@@ -314,9 +371,69 @@
   else
    pupdialog --background pink --backtitle "MoManager: mo edit aborted" --msgbox "You have declined to use the mo file. Ok, it has been left at /tmp/momanager/${ATEXTDOMAIN}.mo and will not be used." 0 0
   fi
   export LANG=$ORIGLANG
   exec momanager reenter
-
+ ;;
+ edit_desk|create_desk)
+  if [ "$EXIT" = "edit_desk" ];then
+   DESKFILE="`echo -n "$YESDESK_COMBO" | cut -f 1 -d ' '`"
+   APKGNAME="`echo -n "$YESDESK_COMBO" | cut -f 2 -d '(' | cut -f 1 -d ')'`"
+   cp -f -a /usr/share/applications/$DESKFILE /tmp/momanager/
+  else
+   DESKFILE="`echo -n "$NODESK_COMBO" | cut -f 1 -d ' '`"
+   APKGNAME="`echo -n "$NODESK_COMBO" | cut -f 2 -d '(' | cut -f 1 -d ')'`"
+   cp -f -a /usr/share/applications/$DESKFILE /tmp/momanager/
+   sed -i -e "s%^Name=%Name[${ORIGLANG1}]=PLEASE INSERT YOUR TRANSLATION HERE\\nName=%" /usr/share/applications/$DESKFILE
+  fi
+  sync
+  killall geany 2>/dev/null
+  echo '#!/bin/sh
+  sleep 3
+  yaf-splash -bg yellow -placement top -timeout 9 -text "The menu file is now open in a text editor. Edit, then Save, then Quit text editor..."
+  ' > /tmp/momanager/yafmsg3
+  chmod 755 /tmp/momanager/yafmsg3
+  /tmp/momanager/yafmsg3 & #msg has delay so will appear on top of text editor window.
+  ASTAT="`stat --format=%y "/usr/share/applications/$DESKFILE" | cut -f 1 -d ' ' | tr -d '-' `" #so can check against file version in latest Woof.
+  [ -f ${PATHPREFIX}/usr/share/applications/$DESKFILE ] && ASTAT="`stat --format=%y "${PATHPREFIX}/usr/share/applications/$DESKFILE" | cut -f 1 -d ' ' | tr -d '-' `" #get orig modify date.
+  xASTAT1="`stat --format=%Y "/usr/share/applications/$DESKFILE"`" #seconds since epoch.
+  defaulttexteditor /usr/share/applications/$DESKFILE
+  xASTAT2="`stat --format=%Y "/usr/share/applications/$DESKFILE"`" #seconds since epoch.
+  if [ "`grep 'PLEASE INSERT YOUR TRANSLATION HERE' /usr/share/applications/$DESKFILE`" != "" ];then
+   mv -f /tmp/momanager/$DESKFILE /usr/share/applications/
+   xASTAT2="$xASTAT1"
+  fi
+  if [ "$xASTAT1" = "$xASTAT2" ];then
+   export LANG=$ORIGLANG
+   exec momanager reenter
+  fi
+  yaf-splash -bg '#80FF80' -timeout 3 -text "The menu is being updated..." &
+  /usr/sbin/fixmenus
+  if [ "`pidof jwm`" != "" ];then
+   JWMVER=`jwm -v|head -n1|cut -d ' ' -f2|cut -d - -f2`
+   if vercmp $JWMVER lt 574;then
+    jwm -restart
+   else
+    jwm -reload
+   fi
+  fi
+  cp -f /usr/share/applications/$DESKFILE /root/
+  cd /root
+  gzip $DESKFILE
+  mv -f ${DESKFILE}.gz ${ASTAT}_${ADATE}_${ATRANSLANG}_${DESKFILE}.gz
+  case $APKGNAME in
+   WOOF)
+    DONEMSG="As this menu file is from Woof, please email it to Barry Kauler \Zbbkauler@gmail.com\ZB, so that all future builds of Puppy may benefit from your translation!"
+   ;;
+   UNKNOWN)
+    DONEMSG="It is not known which package this menu file is from. However, if you can find out, please email your translated menu file to the maintainer of that package."
+   ;;
+   *)
+    DONEMSG="The menu file is part of package ${APKGNAME}. If you can find out the email address of the maintainer of that package, please email your updated translation, it will be appreciated!"
+   ;;
+  esac
+  pupdialog --background green --colors --backtitle "MoManager: Menu edit completed" --msgbox "You have edited \Zb${DESKFILE}\ZB and the menu has been refreshed. The updated menu file has been gzipped and copied to the /root folder, as file \Zb${ASTAT}_${ADATE}_${ATRANSLANG}_${DESKFILE}.gz\ZB. ${DONEMSG}" 0 0
+  export LANG=$ORIGLANG
+  exec momanager reenter
  ;;
 esac