fixaltlanguages.sh 2.5 KB

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