fixduplicatelangkey.sh 964 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # Helps find duplicate translation keys in language files
  3. #
  4. # Copyright (C) 2014 Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
  5. # Syntax
  6. if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
  7. then
  8. echo "Detect duplicate translation keys inside a file (there is no cross file check)."
  9. echo "Usage: detectduplicatelangkey.sh (list|fix)"
  10. fi
  11. if [ "x$1" = "xlist" ]
  12. then
  13. for file in `find htdocs/langs/en_US -name *.lang -type f`
  14. do
  15. dupes=$(
  16. sed "s/^\s*//" "$file" | # Remove any leading whitespace
  17. sed "s/\s*\=/=/" | # Remove any whitespace before =
  18. grep -Po "(^.*?)=" | # Non greedeely match everything before =
  19. sed "s/\=//" | # Remove trailing = so we get the key
  20. sort | uniq -d # Find duplicates
  21. )
  22. if [ -n "$dupes" ]
  23. then
  24. echo "Duplicates found in $file"
  25. echo "$dupes"
  26. fi
  27. done
  28. fi
  29. # To convert
  30. if [ "x$1" = "xfix" ]
  31. then
  32. echo Feature not implemented. Please fix files manually.
  33. fi