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