foreman/lib/tasks/locale.rake @ ad01d4d2
fd2e3be1 | Lukas Zapletal | require "fileutils"
|
|
desc 'Locale specific tasks: locale:find'
|
|||
namespace :locale do
|
|||
desc 'Extract strings from model'
|
|||
task :find_model => "gettext:store_model_attributes" do
|
|||
# Add some extra comments for translators and remove the following entires:
|
|||
#
|
|||
# something/something
|
|||
# Puppet::something
|
|||
#
|
|||
ignored = /_\('(\w+\/\w+|Puppet:)/
|
|||
filename = "locale/model_attributes"
|
|||
File.rename "#{filename}.rb", "#{filename}.tmp"
|
|||
File.open("#{filename}.rb", "w") do |output|
|
|||
IO.foreach("#{filename}.tmp") do |line|
|
|||
if not line =~ /^\s*#/ and not line =~ ignored
|
|||
output.puts '# TRANSLATORS: "Table name" or "Table name|Column name" for error messages'
|
|||
output.puts line
|
|||
end
|
|||
end
|
|||
end
|
|||
FileUtils.rm "#{filename}.tmp"
|
|||
end
|
|||
bb52de13 | Lukas Zapletal | desc 'Extract strings from codebase'
|
|
d5a28dec | Lukas Zapletal | task :find_code => ["gettext:find", "gettext:po_to_json"]
|
|
bb52de13 | Lukas Zapletal | ||
fd2e3be1 | Lukas Zapletal | desc 'Extract strings from model and from codebase'
|
|
bb52de13 | Lukas Zapletal | task :find => [:find_model, :find_code] do
|
|
77871d22 | Lukas Zapletal | # do not commit PO string merge into git (we are using transifex.com)
|
|
`git checkout -- locale/*/*.po`
|
|||
# find malformed strings
|
|||
bb52de13 | Lukas Zapletal | errors = File.open("locale/foreman.pot") {|f| f.grep /(%s.*%s|#\{)/}
|
|
if errors.count > 0
|
|||
74e0b0e3 | Lukas Zapletal | errors.each {|e| puts "MALFORMED: #{e}"}
|
|
bb52de13 | Lukas Zapletal | puts "Malformed strings found: #{errors.count}"
|
|
puts "Please read http://projects.theforeman.org/projects/foreman/wiki/Translating"
|
|||
end
|
|||
end
|
|||
fd2e3be1 | Lukas Zapletal | ||
c4da9ff7 | Lukas Zapletal | desc 'Alias for gettext:pack'
|
|
task :pack => "gettext:pack"
|
|||
fd2e3be1 | Lukas Zapletal | end
|