diff --git a/lib/noosfero/i18n.rb b/lib/noosfero/i18n.rb index 46ac9c2..f452c30 100644 --- a/lib/noosfero/i18n.rb +++ b/lib/noosfero/i18n.rb @@ -4,6 +4,8 @@ class Object include FastGettext::Translation alias :gettext :_ alias :ngettext :n_ + alias :c_ :_ + alias :cN_ :N_ end @@ -13,6 +15,11 @@ if File.exists?(custom_locale_dir) repos << FastGettext::TranslationRepository.build('environment', :type => 'po', :path => custom_locale_dir) end +Dir.glob('{baseplugins,config/plugins}/*/locale') do |plugin_locale_dir| + plugin = File.basename(File.dirname(plugin_locale_dir)) + repos << FastGettext::TranslationRepository.build(plugin, :type => 'mo', :path => plugin_locale_dir) +end + # translations in place? locale_dir = Rails.root.join('locale') if File.exists?(locale_dir) diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index 7006ccf..43cbcea 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -16,6 +16,14 @@ file makemo_stamp => Dir.glob('po/*/noosfero.po') do 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 @@ -54,7 +62,6 @@ task :updatepo do 'config/initializers/*.rb', 'public/*.html.erb', 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}', - 'plugins/**/{controllers,models,lib,views}/**/*.{rhtml,html.erb,rb}', ].map { |pattern| Dir.glob(pattern) }.flatten require 'gettext' @@ -67,7 +74,31 @@ task :updatepo do po_root: 'po', } ) +end +Dir.glob('plugins/*').each do |plugindir| + plugin = File.basename(plugindir) + task :updatepo => "updatepo: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 + end + sh 'find', po_root, '-type', 'd', '-empty', '-delete' + puts + end end task :checkpo do diff --git a/script/move-translations-to-plugins.rb b/script/move-translations-to-plugins.rb new file mode 100644 index 0000000..342d054 --- /dev/null +++ b/script/move-translations-to-plugins.rb @@ -0,0 +1,34 @@ +languages = Dir.glob('po/*').reject { |f| f =~ /pot$/ }.map { |f| File.basename(f) } + +core_files = `grep '#:' po/noosfero.pot | cut -d ':' -f 2 | sed 's/^\s*//' | grep -v '^plugins' | sort -u`.split.map { |f| [ '-N', f] }.flatten + +languages.each do |lang| + + lang_plugins_po = "tmp/#{lang}_plugins.po" + system('msggrep', '-v', *core_files, '--output-file', lang_plugins_po, "po/#{lang}/noosfero.po") + + Dir.glob('plugins/*').each do |plugindir| + plugin = File.basename(plugindir) + po = File.join(plugindir, 'po', lang, plugin + '.po') + + files = [] + Dir.glob("#{plugindir}/**/*.{rb,html.erb}").each do |f| + files << '-N' << f + end + + system('mkdir', '-p', File.dirname(po)) + system('msggrep', *files, '--output-file', po, lang_plugins_po) + + if system("msgfmt --statistics -o /dev/null #{po} 2>&1 | grep -q '^0 translated message'") + # empty .po + system('rm', '-f', po) + puts "[#{lang}] #{plugin}: PO file empty, deleted" + else + puts "[#{lang}] #{plugin}" + end + + end + + system('rm', '-f', lang_plugins_po) + system('find plugins/*/po -type d -empty -delete') +end -- libgit2 0.21.2