Skip to content

Instantly share code, notes, and snippets.

@stas
Created October 9, 2011 01:15
Show Gist options
  • Select an option

  • Save stas/1273142 to your computer and use it in GitHub Desktop.

Select an option

Save stas/1273142 to your computer and use it in GitHub Desktop.
require 'gettext/tools.rb'
require 'tenjin'
require 'ruby_parser'
require 'gettext_i18n_rails/ruby_gettext_extractor'
begin
require 'gettext/tools/rgettext'
rescue LoadError #version prior to 2.0
require 'gettext/rgettext'
end
##
# Gettext parser for `fast_gettext` gem
# This should fix template tags like these `#{_'String'}` in Tenjin
#
# Invoke with `rgettext -r ./tenjin_gettext_parser.rb view/*`
module GettextI18nRails
module TenjinParser
module_function
def target?(file)
File.extname(file) == '.rbhtml'
end
def parse(file, msgids = [])
tmpl = Tenjin::Template.new
code = tmpl.convert_file(file)
RubyGettextExtractor.parse_string(code, file, msgids)
end
end
end
GetText::RGetText.add_parser(GettextI18nRails::TenjinParser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment