check_translations.rb 943 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env ruby
  2. MASTER="en-gb"
  3. DIR = "#{__dir__}/.."
  4. keys = %x[sed -r 's/.*(\\['.*'\\]\\['.*'\\]).*/\\1/g' #{DIR}/data/web/lang/lang.#{MASTER}.php | grep '^\\\[' | sed 's/\\[/\\\\[/g' | sed 's/\\]/\\\\]/g'|sort | uniq]
  5. not_used_in_php = []
  6. keys.split("\n").each do |key|
  7. %x[git grep "#{key}" -- #{DIR}/data/web/*.php #{DIR}/data/web/inc #{DIR}/data/web/modals]
  8. if $?.exitstatus > 0
  9. not_used_in_php << key
  10. end
  11. end
  12. # \['user'\]\['username'\]
  13. # \['user'\]\['waiting'\]
  14. # \['warning'\]\['spam_alias_temp_error'\]
  15. not_used = []
  16. not_used_in_php.each do |string|
  17. section = string.scan(/([a-z]+)/)[0][0]
  18. key = string.scan(/([a-z]+)/)[1][0]
  19. %x[git grep lang.#{key} -- #{DIR}/data/web/js/#{section}.js #{DIR}/data/web/js/debug.js]
  20. if $?.exitstatus > 0
  21. not_used << string
  22. end
  23. end
  24. puts "# Remove unused translation keys:"
  25. not_used.each do |key|
  26. puts "sed -i \"/\\$lang#{key}.*;/d\" data/web/lang/lang.??.php"
  27. end