Rails: Logs translations during tests so that dynamic translations can be found through Gettext
Ruby
Permalink
Failed to load latest commit information.
lib use FastGettext::PoFile instead of clumsy GetText interface Mar 31, 2009
spec modernize Sep 23, 2011
tasks rake to tasks folder Feb 26, 2009
.gitignore gemspec + better examples Jan 27, 2009
Gemfile modernize Sep 23, 2011
Gemfile.lock modernize Sep 23, 2011
Rakefile update gem Sep 23, 2011
Readme.md update gem Sep 23, 2011
VERSION update gem Sep 23, 2011
gettext_test_log.gemspec Regenerate gemspec for version 0.2.1 Sep 23, 2011
init.rb modernize Sep 23, 2011

Readme.md

Problem

  • Finding all translations by parsing is impossible for dynamic calls
  • often even static calls are not found
  • some file formats do not have a gettext parser

Solution

  • log all translations during test execution
  • write them to an parseable temp file
  • use gettext:find / gettext:pack as usual
  • missing translation = missing test, write tests!

This will only work with FastGettext and RSpec for now!

Install

  • rails plugin install git://github.com/grosser/gettext_test_log.git
  • Gem: gem install gettext_test_log

Usage

rake gettext:test_log

Optionally copy+modify task with options: :exclude_msgids_in_po_files=>[ 'some_po_file_that_contains_translations_you_do_not_need.po' ]

Add to your spec_helper: #spec/spec_helper.rb GettextTestLog::activate_test_logging

Run: rake gettext:test_log rake gettext:find #find new translations #fill newly found translations rake gettext:pack #write translations

Examples output

#locale/testlog_phrases.rb
_("Add to favorites")
_("Added a subtitle to %{name}")
_("Additional Information")
_("Address")
...

Unwanted translations

When using gettext_i18n_rails, most of the columns of a model will be translated during model tests this can be annoying since normally no user will see them. To disable this, add to spec/spec_helper.rb : class ActiveRecord::Base def self.human_attribute_name(attr) attr.to_s end end

TODO

  • needs tests... :(
  • make compatible with GetText and FastGettext at the same time ?

Author

Michael Grosser
michael@grosser.it
Hereby placed under public domain, do what you want, just do not hold me accountable...