fixaltlanguages.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. # Recursively deduplicate file lines on a per file basis
  3. # Useful to deduplicate language files
  4. #
  5. # Needs awk 4.0 for the inplace fixing command
  6. #
  7. # Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
  8. # Syntax
  9. if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
  10. then
  11. echo "Scan alternate language files and remove entries found into parent file"
  12. echo "Usage: fixaltlanguages.sh (list|fix) (all|file.lang) [xx_XX]"
  13. exit
  14. fi
  15. if [ "x$2" = "x" ]
  16. then
  17. echo "Scan alternate language files and remove entries found into parent file"
  18. echo "Usage: fixaltlanguages.sh (list|fix) (all|file.lang) [xx_XX]"
  19. exit
  20. fi
  21. # To detect
  22. if [ "x$1" = "xlist" ]
  23. then
  24. echo Feature not available
  25. fi
  26. # To fix
  27. if [ "x$1" = "xfix" ]
  28. then
  29. for dir in `find htdocs/langs/$3* -type d`
  30. do
  31. dirshort=`basename $dir`
  32. #echo $dirshort
  33. export aa=`echo $dirshort | nawk -F"_" '{ print $1 }'`
  34. export bb=`echo $dirshort | nawk -F"_" '{ print $2 }'`
  35. aaupper=`echo $dirshort | nawk -F"_" '{ print toupper($1) }'`
  36. if [ $aaupper = "EN" ]
  37. then
  38. aaupper="US"
  39. fi
  40. bblower=`echo $dirshort | nawk -F"_" '{ print tolower($2) }'`
  41. if [ "$aa" != "$bblower" -a "$dirshort" != "en_US" ]
  42. then
  43. reflang="htdocs/langs/"$aa"_"$aaupper
  44. if [ -d $reflang ]
  45. then
  46. echo "***** Process language "$aa"_"$bb" - Search original into "$reflang
  47. echo $dirshort is an alternative language of $reflang
  48. echo ./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
  49. ./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
  50. for fic in `ls htdocs/langs/${aa}_${bb}/*.delta`; do f=`echo $fic | sed -e 's/\.delta//'`; echo $f; mv $f.delta $f; done
  51. for fic in `ls htdocs/langs/${aa}_${bb}/*.lang`;
  52. do f=`cat $fic | wc -l`;
  53. #echo $f lines into file $fic;
  54. if [ $f = 1 ]
  55. then
  56. echo Only one line remainging into file $fic, we delete it;
  57. rm $fic
  58. fi;
  59. done
  60. fi
  61. fi
  62. done;
  63. fi