From 74f1ee6824f7d2cb08aa7bff3c00f6b69014a00d Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 3 Nov 2015 20:00:13 -0200 Subject: [PATCH] rails4: port translation tasks to Ruby-GetText 3.x --- lib/tasks/gettext.rake | 115 ++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------- lib/tasks/translation.rake | 4 ++-- 2 files changed, 42 insertions(+), 77 deletions(-) diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index d1d6bf3..dc65f05 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -4,37 +4,21 @@ require 'pathname' -makemo_stamp = 'tmp/makemo.stamp' -desc "Create mo-files for L10n" -task :makemo => makemo_stamp -file makemo_stamp => Dir.glob('po/*/noosfero.po') do - Rake::Task['symlinkmo'].invoke - - require 'gettext' - require 'gettext/tools' - GetText.create_mofiles( - verbose: true, - po_root: 'po', - mo_root: 'locale', - ) - - Dir.glob('plugins/*').each do |plugindir| - GetText.create_mofiles( - verbose: true, - po_root: File.join(plugindir, 'po'), - mo_root: File.join(plugindir, 'locale'), - ) - end - - FileUtils.mkdir_p 'tmp' - FileUtils.touch makemo_stamp -end - -task :cleanmo do - rm_f makemo_stamp +require 'gettext/tools/task' +GetText::Tools::Task.define do |task| + task.domain = 'noosfero' + task.enable_po = true + task.po_base_directory = 'po' + task.mo_base_directory = 'locale' + task.files = [ + "{app,lib}/**/*.{rb,rhtml,erb}", + 'config/initializers/*.rb', + 'public/*.html.erb', + 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}', + ].map { |pattern| Dir.glob(pattern) }.flatten end -task :clean => 'cleanmo' +task 'gettext:mo:update' => :symlinkmo task :symlinkmo do langmap = { 'pt' => 'pt_BR', @@ -55,57 +39,38 @@ task :symlinkmo do end end -desc "Update pot/po files to match new version." -task :updatepo do - - puts 'Extracting strings from source. This may take a while ...' - - # XXX this list is duplicated in test/unit/i18n_test.rb; if you change it - # here, please also update it there. - files_to_translate = [ - "{app,lib}/**/*.{rb,rhtml,erb}", - 'config/initializers/*.rb', - 'public/*.html.erb', - 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}', - ].map { |pattern| Dir.glob(pattern) }.flatten - - require 'gettext' - require 'gettext/tools' - GetText.update_pofiles( - 'noosfero', - files_to_translate, - Noosfero::VERSION, - { - po_root: 'po', - } - ) -end - Dir.glob('plugins/*').each do |plugindir| plugin = File.basename(plugindir) - task :updatepo => "updatepo:plugin:#{plugin}" + po_root = File.join(plugindir, 'po') + next if Dir["#{po_root}/**/*.po"].empty? + + namespace "noosfero:plugin:#{plugin}" do + GetText::Tools::Task.define do |task| + task.domain = plugin + task.enable_po = true + task.po_base_directory = po_root + task.mo_base_directory = File.join(plugindir, 'locale') + task.files = Dir["#{plugindir}/**/*.{rb,html.erb}"] + end + + task "gettext:po:cleanup" do + plugin_pot = File.join(po_root, plugin + '.pot') + if File.exists?(plugin_pot) && system("LANG=C msgfmt --statistics --output /dev/null #{plugin_pot} 2>&1 | grep -q '^0 translated messages.$'") + rm_f plugin_pot + end + sh 'find', po_root, '-type', 'd', '-empty', '-delete' + end - desc "Extract strings from #{plugin} plugin" - task "updatepo:plugin:#{plugin}" do - files = Dir.glob("#{plugindir}/**/*.{rb,html.erb}") - po_root = File.join(plugindir, 'po') - require 'gettext' - require 'gettext/tools' - GetText.update_pofiles( - plugin, - files, - Noosfero::VERSION, - { - po_root: po_root, - } - ) - plugin_pot = File.join(po_root, "#{plugin}.pot") - if File.exists?(plugin_pot) && system("LANG=C msgfmt --statistics --output /dev/null #{plugin_pot} 2>&1 | grep -q '^0 translated messages.$'") - rm_f plugin_pot + task "gettext:po:update" do + Rake::Task["noosfero:plugin:#{plugin}:gettext:po:cleanup"].invoke + end + task "gettext:mo:update" do + Rake::Task["noosfero:plugin:#{plugin}:gettext:po:cleanup"].invoke end - sh 'find', po_root, '-type', 'd', '-empty', '-delete' - puts end + + task 'gettext:po:update' => "noosfero:plugin:#{plugin}:gettext:po:update" + task 'gettext:mo:update' => "noosfero:plugin:#{plugin}:gettext:mo:update" end def checkpo(po_files) diff --git a/lib/tasks/translation.rake b/lib/tasks/translation.rake index 00b6fcb..0291883 100644 --- a/lib/tasks/translation.rake +++ b/lib/tasks/translation.rake @@ -2,10 +2,10 @@ namespace :noosfero do namespace :translations do desc 'Update all translation files' - task :update => ['updatepo', 'noosfero:doc:rebuild'] + task :update => ['gettext:po:update', 'noosfero:doc:rebuild'] desc 'Compiles all translations' - task :compile => ['makemo', 'noosfero:doc:translate'] + task :compile => ['gettext:mo:update', 'noosfero:doc:translate'] end end -- libgit2 0.21.2