1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-12-14 10:52:49 +02:00
mailcow-dockerized/helper-scripts/check_translations.rb
David Escala 8ae5077775 Remove unused language keys from data/web/lang/lang.*.php
helper-scripts/check_translations.rb checks if keys present in the master
translation file are used in any php or js code.  Writes a sed comand to
stdout to remove unused keys from all lang files.

This saves unnecessary work when translating.
2018-02-09 18:56:06 +01:00

35 lines
908 B
Ruby
Executable File

#!/usr/bin/ruby
MASTER="en"
DIR = "#{__dir__}/.."
keys = %x[sed -r 's/.*(\\['.*'\\]\\['.*'\\]).*/\\1/g' #{DIR}/data/web/lang/lang.#{MASTER}.php | grep '^\\\[' | sed 's/\\[/\\\\[/g' | sed 's/\\]/\\\\]/g'|sort | uniq]
not_used_in_php = []
keys.split("\n").each do |key|
%x[git grep "#{key}" -- #{DIR}/data/web/*.php #{DIR}/data/web/inc #{DIR}/data/web/modals]
if $?.exitstatus > 0
not_used_in_php << key
end
end
# \['user'\]\['username'\]
# \['user'\]\['waiting'\]
# \['warning'\]\['spam_alias_temp_error'\]
not_used = []
not_used_in_php.each do |string|
section = string.scan(/([a-z]+)/)[0][0]
key = string.scan(/([a-z]+)/)[1][0]
%x[git grep lang.#{key} -- #{DIR}/data/web/js/#{section}.js]
if $?.exitstatus > 0
not_used << string
end
end
puts "# Remove unused translation keys:"
not_used.each do |key|
puts "sed -i \"/\\$lang#{key}.*;/d\" data/web/lang/lang.??.php"
end