UpstreamToKDE

transfer-upstream-to-kde.sh

   1 #!/bin/bash
   2 ### How to transfer upstream to KDE translations that are done on Launchpad.
   3 
   4 ######################################################################################
   5 ## How to get all the translations from the Launchpad
   6 ######################################################################################
   7 ##
   8 ## Reference:
   9 ## https://wiki.ubuntu.com/Translations/KnowledgeBase/Exporting#Full
  10 ##
  11 ## Where to get them:
  12 ## https://translations.launchpad.net/ubuntu/natty/+language-packs
  13 ##
  14 ## Get the base pack and the latest update:
  15 ## wget http://launchpadlibrarian.net/70194188/ubuntu-natty-translations.tar.gz
  16 ## wget http://launchpadlibrarian.net/71172166/ubuntu-natty-translations-update.tar.gz
  17 ######################################################################################
  18 
  19 ### downloaded language packs
  20 translations="./ubuntu-natty-translations.tar.gz"
  21 translations_update="./ubuntu-natty-translations-update.tar.gz"
  22 
  23 ### set the code of the language to be extracted
  24 lng="sq"
  25 
  26 ### get the names of the files corresponding to the given language
  27 tar tvfz ubuntu-natty-translations.tar.gz | grep "/$lng/" | gawk '{print $6}' > extract-files.txt
  28 
  29 ### extract these files from the language pack archives
  30 ### after the extraction, there will be a directory named:
  31 ### rosseta-natty/$lng/LC_MESSAGES
  32 tar --extract --gunzip --files-from=extract-files.txt --overwrite --file=$translations
  33 tar --extract --gunzip --files-from=extract-files.txt --overwrite --file=$translations_update
  34 
  35 ### get the names of all the translation files in kde templates
  36 find l10n-kde4/templates/messages/ -name '*.pot' | sed -e 's!^.*/!!' -e 's/t$//' > po-files.txt
  37 
  38 
  39 ### copy relevant traslated files to a temporary directory
  40 check_dir="${lng}1/"
  41 mkdir -p $check_dir
  42 for file in $(cat po-files.txt)
  43 do
  44   echo $file
  45   cp rosetta-natty/$lng/LC_MESSAGES/$file $check_dir
  46 done
  47 
  48 ### several checks for errors
  49 ### see also:
  50 ### http://i18n.kde.org/docs/translation-howto/check-gui.html
  51 ### http://translate.sourceforge.net/wiki/toolkit/using_pofilter
  52 msgfmt --check $lng_dir/
  53 scripts/msgfmt-test.sh $lng_dir/*.po
  54 pofilter -i $check_dir -o ${check_dir}_err \
  55          --kde -t accelerators -t escapes -t nplurals -t tab -t xmltags
  56 
  57 ### try to fix all the errors and when everything is OK
  58 ### commit PO files to the l10n-kde SVN
  59 
  60 ### transfer checked files to the working dir of l10n-kde
  61 find l10n-kde4/templates/messages/ -name '*.pot' > pot-files.txt
  62 for pot_file in $(cat pot-files.txt)
  63 do
  64   dir=$(dirname $pot_file)
  65   dir=${dir##templates/messages/}  ## remove leading path: templates/messages/
  66   file=$(basename $pot_file)
  67   file=${file%%t}  ## remove the trailing 't' (so that extension becomes .po)
  68 
  69   if [ -f $check_dir/$file ]
  70   then
  71     mkdir -p l10n-kde4/$lng/messages/$dir
  72     cp $check_dir/$file l10n-kde4/$lng/messages/$dir/
  73     # echo $file
  74   fi
  75 done
  76 
  77 ### add the new files to the l10n-kde SVN and commit
  78 cd l10n-kde4/$lng/messages/
  79 svn status | grep '?' | gawk '{print $2}' | xargs svn add
  80 svn commit -m 'importing upstream to kde PO files modified on launchpad'
  81 
  82 ### clean up
  83 # cd $(dirname $0)
  84 # rm extract-files.txt
  85 # rm $translations
  86 # rm po-files.txt
  87 # rm pot-files.txt
  88 # rm translations_update
  89 # rm -rf $check_dir
  90 # rm -rf ${check_dir}_err
  91 


msgfmt-test.sh

   1 #!/bin/bash
   2 
   3 ### http://www.translate.org.za/blogs/dwayne/en/content/continuous-integration-can-it-work-software-localisation
   4 
   5 files=$*
   6 
   7 # local variables
   8 message=""
   9 body=""
  10 failures=0
  11 successes=0
  12 
  13 function failure
  14 {
  15   pofile=$1
  16   body=$(echo $body; echo "\n"; echo "$message\n\n")
  17   message=""
  18   failures=$(($failures + 1))
  19 }
  20 
  21 function success
  22 {
  23   pofile=$1
  24   body=$(echo $body; echo "\n")
  25   message=""
  26   successes=$(($successes + 1))
  27 }
  28 
  29 function run_msgfmt
  30 {
  31   pofile=$1
  32   exit_status=$(msgfmt -cv -o /dev/null $pofile 2>/dev/null > /dev/null; echo $?)
  33   message=$(msgfmt -cv -o /dev/null $pofile 2>/dev/stdout | while read i; do echo "$i\n" ; done)
  34   return $exit_status
  35 }
  36 
  37 function print_header
  38 {
  39   echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  40   echo ""
  41 }
  42 
  43 function print_body
  44 {
  45   cat -
  46   echo -e $body
  47 }
  48 
  49 function print_footer
  50 {
  51   cat -
  52   echo ""
  53 }
  54 
  55 for pofile in $files
  56 do
  57   run_msgfmt $pofile && success $pofile || failure $pofile
  58 done
  59 
  60 print_header |
  61 print_body |
  62 print_footer

UpstreamToKDE (last edited 2011-05-10 06:42:44 by dashohoxha)