Aller au contenu

Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/cpcleaned2bin.sh

Un livre de Wikilivres.
  • cpcleaned2bin function is used to product pseudo binary executable file without extention .sh and without tags #D #M #O #P #T The file is coped to bin directory.
  • If there is "gettext" in parameter, the gettext is replaced by $" to product pot file and if potfile is created then copy under .po file in fr and es lang directories.
  • If .mo file pre-exist then it is updated.
  • NOTE: Bindir Resourcesdir Srcdir Verbose variables must be defined in the calling program

cpcleaned2bin.sh (cpcleaned2bin function)

[modifier | modifier le wikicode]
#!/bin/bash
#H File cpcleaned2bin.sh cpcleand2bin in annex.lib
#H Bindir Resourcesdir Srcdir Verbose variables are defined in the calling program 
VERSION=211020
function cpcleaned2bin ()
{
	if [ "$1" = "--v" ]; then echo "cpcleaned2bin version : $VERSION";return 0;fi	  
    mkdir -p ./tmp 
	if test -e $Srcdir/$1; then echo; else echo "$Srcdir/$1 not found by function cpcleaned2bin."; return -1;fi
	awk '{
      if ($1=="#D" || $1=="#M" || $1=="#O" || $1=="#P" || $1=="#T")  {;} # do not replace with an empty line
      else {print $0} 
	  }' $Srcdir/$1 > ./tmp/$1.cleaned-1
	#T cat $Srcdir/$1 | grep -v "#O\|#M\|#P\|#T" > ./tmp/$1.cleaned-1
	cat ./tmp/$1.cleaned-1 | sed "s/eval_gettext /echo \$/g" | sed "s/; echo//g" > ./tmp/$1.cleaned-2
    cat ./tmp/$1.cleaned-2 | sed "s/\"\$(gettext '/\$\"/g" | sed "s/' )//g" | sed "s/')//g" > ./tmp/$1.cleaned-3
	echo $1 | sed "s/.sh//g" | sed "s/.bash//g" > ./tmp/first.txt
	read First < ./tmp/first.txt
	#T echo "First = $First" 
	cat ./tmp/$1.cleaned-3 > $Bindir/$First
    if echo $Bindir/$First | grep ".inc"; then chmod 644 $Bindir/$First; else chmod 755 $Bindir/$First; fi

	if cat $Bindir/$First | grep -e '$\"'
	then
      xgettext -L shell -o $Resourcesdir/lang/po/$First.pot --from-code=UTF-8 $Bindir/$First	
      if test -z $Resourcesdir/lang/po/fr/$First.po
      then 
	    cp $Resourcesdir/lang/po/$First.pot $Resourcesdir/lang/po/fr/$First.po
      else 
	    msgmerge --update $Resourcesdir/lang/po/fr/$First.po $Resourcesdir/lang/po/$First.pot
	  fi    	
      msgfmt $Resourcesdir/lang/po/fr/$First.po -o $Resourcesdir/lang/po/fr/$First.mo
      echo -e "\033[1;33m### Only if you are edit and update $First.po with Poedit: ###\033[0m"
      echo "copy $Resourcesdir/lang/po/fr/$First.mo to /usr/share/locale/fr/LC_MESSAGES/$First.mo"    
      if test -z $Resourcesdir/lang/po/es/$First.po
      then 
	    cp $Resourcesdir/lang/po/$First.pot $Resourcesdir/lang/po/es/$First.po
      else 
	    msgmerge --update $Resourcesdir/lang/po/es/$First.po $Resourcesdir/lang/po/$First.pot
      fi
      msgfmt $Resourcesdir/lang/po/es/$First.po -o $Resourcesdir/lang/po/es/$First.mo
      echo -e "\033[1;33m### Only if you are edit and update $First.po with Poedit: ###\033[0m"
      echo "copy $Resourcesdir/lang/po/es/$First.mo to /usr/share/locale/es/LC_MESSAGES/$First.mo"
	fi
    rm -r ./tmp
	if [ "$Verbose" = "true" ];then echo "$Bindir/$First is updated:"; ls -l $Bindir/$First; fi
}

#D cpcleaned2bin function documentation
#D ------------------------------------
#D cpcleaned2bin function is used to product pseudo binary executable file
#D without extention .sh and without tags #D #M #O #P #T The file is coped
#D to bin directory.
#D If exist "gettext" in first parameter the gettext is replaced by $" to
#D product pot file and if potfile is created then copy under .po file in 
#D fr and es lang directories.
#D If .mo file pre-exist then it is updated.
#D NOTE: Bindir Resourcesdir Srcdir Verbose variables must be defined in the
#D calling program

test_cpcleadned2bin.bash

[modifier | modifier le wikicode]
#!/bin/bash
#H File : test_cpcleadned2bin.bash in ~/Add_appendix/tests/1-annex.lib/14-cpclineaned2bin.sh

VERSION=211014

clear
echo "syntax of $0 [ --docu ]"

source cpcleaned2bin.sh

Srcdir='../../01-sbsrc'
mkdir -p ./bin
Bindir=./bin
Verbose="true"

cpcleaned2bin --v; echo "----"
sleep 5
cpcleaned2bin cp-src2bin.sh

if [ "$1" = "--docu" ] && test -d ../../../sbin/doc; then
clear; echo "$0 version $VERSION"; echo "----"
cat cpcleaned2bin.sh | grep "#D" | tee ../../../sbin/doc/cpcleaned2bin.docu
fi