You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GetText's ERB parser uses the standard ERB library, while Rails uses Erubis which has some syntax extensions, such as -%> to avoid adding empty lines to the output. It also uses RubyParser to parse the generated code, which has the same problems solved by the RubyGettextExtractor included in gettext_i18n_rails.
To work around this I added the following code in lib/tasks/gettext.rake:
# use the Ruby parser from gettext_i18n_rails, which supports "#{_('...')}" syntaxrequire'gettext_i18n_rails/ruby_gettext_extractor'GetText::Tools::XGetText.add_parser(RubyGettextExtractor)# add a custom ERB parser which uses Erubis and RubyGettextExtractorclassErubisGettextExtractor < GetText::ErbParserdefself.target?(file)File.extname(file) == '.erb'end# adapted from gettext/tools/parser/erb.rbdefparsecontent=IO.read(@path)src=ActionView::Template::Handlers::Erubis.new(content).src# Force the src encoding back to the encoding in magic comment# or original content.encoding=detect_encoding(src) || content.encodingsrc.force_encoding(encoding)# Remove magic comment prepended by erb in Ruby 1.9.src=src.gsub(MAGIC_COMMENT,"")RubyGettextExtractor.parse_string(src,@path)endendGetText::Tools::XGetText.add_parser(ErubisGettextExtractor)
It would be great if something like this could be included in the gem, and both of these extractors could either be made the default, or at least mentioned in the README ;-)
The text was updated successfully, but these errors were encountered:
GetText's ERB parser uses the standard ERB library, while Rails uses Erubis which has some syntax extensions, such as
-%>
to avoid adding empty lines to the output. It also uses RubyParser to parse the generated code, which has the same problems solved by theRubyGettextExtractor
included in gettext_i18n_rails.To work around this I added the following code in
lib/tasks/gettext.rake
:It would be great if something like this could be included in the gem, and both of these extractors could either be made the default, or at least mentioned in the README ;-)
The text was updated successfully, but these errors were encountered: