diff options
-rw-r--r-- | lib/tasks/gettext.rake | 42 | ||||
-rwxr-xr-x | script/generate_pot.sh | 22 |
2 files changed, 23 insertions, 41 deletions
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index ace7205ae..366dfbe88 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -9,27 +9,31 @@ namespace :gettext do end end - desc "Update pot file only, without fuzzy guesses (these are done by Transifex)" - task :findpot => :environment do + desc "Update pot/po files for a theme." + task :find_theme => :environment do + theme = ENV['THEME'] + unless theme + puts "Usage: Specify an Alaveteli-theme with THEME=[theme directory name]" + exit(0) + end load_gettext - $LOAD_PATH << File.join(File.dirname(__FILE__),'..','..','lib') - require 'gettext_i18n_rails/haml_parser' - files = files_to_translate + msgmerge = Rails.application.config.gettext_i18n_rails.msgmerge + msgmerge ||= %w[--sort-output --no-location --no-wrap] + GetText.update_pofiles_org( + text_domain, + theme_files_to_translate(theme), + "version 0.0.1", + :po_root => theme_locale_path(theme), + :msgmerge => msgmerge + ) + end - #write found messages to tmp.pot - temp_pot = "tmp.pot" - GetText::rgettext(files, temp_pot) + def theme_files_to_translate(theme) + Dir.glob("{vendor/plugins/#{theme}/lib}/**/*.{rb,erb}") + end - #merge tmp.pot and existing pot - FileUtils.mkdir_p('locale') - GetText::msgmerge("locale/app.pot", temp_pot, "alaveteli", :po_root => 'locale', :msgmerge=>[ :no_wrap, :sort_output ]) - Dir.glob("locale/*/app.po") do |po_file| - GetText::msgmerge(po_file, temp_pot, "alaveteli", :po_root => 'locale', :msgmerge=>[ :no_wrap, :sort_output ]) - end - File.delete(temp_pot) - end + def theme_locale_path(theme) + File.join(Rails.root, "vendor", "plugins", theme, "locale-theme") + end - def files_to_translate - Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,rhtml}") - end end diff --git a/script/generate_pot.sh b/script/generate_pot.sh deleted file mode 100755 index c0540c3d9..000000000 --- a/script/generate_pot.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -echo "This is NOT a completed script! Just use it as reference for what to do from the command line, or fix it until it works!" -exit 1 - -cd `dirname $0` -# grab latest po files from Transifex -tx pull -a -f -git status | grep app.po | awk '{print $3}' | xargs git add -git commit -m "Backup latest po files from Transifex" - -# now regenerate POT and PO files from Alaveteli source -bundle exec rake gettext:store_model_attributes -bundle exec rake gettext:findpot - -# upload the result to Transifex -tx push -t - -# re-download (it removes the fuzzy strings and normalises it to the format last committed) -tx pull -a -f -git status | grep app.po | awk '{print $3}' | xargs git add -git commit -m "Updated POT" |