fixduplicatelangkey.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. echo "Search duplicate keys into en_US lang files (there is no cross file check)"
  14. for file in `find htdocs/langs/en_US -name *.lang -type f`
  15. do
  16. dupes=$(
  17. sed "s/^\s*//" "$file" | # Remove any leading whitespace
  18. sed "s/\s*\=/=/" | # Remove any whitespace before =
  19. grep -Po "(^.*?)=" | # Non greedeely match everything before =
  20. sed "s/\=//" | # Remove trailing = so we get the key
  21. sort | uniq -d # Find duplicates
  22. )
  23. if [ -n "$dupes" ]
  24. then
  25. echo "Duplicates found in $file"
  26. echo "$dupes"
  27. fi
  28. done
  29. fi
  30. # To convert
  31. if [ "x$1" = "xfix" ]
  32. then
  33. echo Feature not implemented. Please fix files manually.
  34. fi