fixaltlanguages.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if [ $aaupper = "EL" ]
  41. then
  42. aaupper="GR"
  43. fi
  44. if [ $bb = "EG" ]
  45. then
  46. aaupper="SA"
  47. fi
  48. bblower=`echo $dirshort | nawk -F"_" '{ print tolower($2) }'`
  49. echo "***** Process language "$aa"_"$bb
  50. if [ "$aa" != "$bblower" -a "$dirshort" != "en_US" ]
  51. then
  52. reflang="htdocs/langs/"$aa"_"$aaupper
  53. echo $reflang" "$aa"_"$bb != $aa"_"$aaupper
  54. # If $reflang is a main language to use to sanitize the alternative file
  55. if [ -d $reflang -a $aa"_"$bb != $aa"_"$aaupper ]
  56. then
  57. echo "***** Search original into "$reflang
  58. echo $dirshort is an alternative language of $reflang
  59. echo ./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
  60. ./dev/translation/strip_language_file.php $aa"_"$aaupper $aa"_"$bb $2
  61. for fic in `ls htdocs/langs/${aa}_${bb}/*.delta`; do f=`echo $fic | sed -e 's/\.delta//'`; echo $f; mv $f.delta $f; done
  62. for fic in `ls htdocs/langs/${aa}_${bb}/*.lang`;
  63. do f=`cat $fic | wc -l`;
  64. #echo $f lines into file $fic;
  65. if [ $f = 1 ]
  66. then
  67. echo Only one line remainging into file $fic, we delete it;
  68. rm $fic
  69. fi;
  70. done
  71. fi
  72. fi
  73. done;
  74. fi