Sunday, July 31, 2011

Reuse gettext gem to parse .po file

I am working on a translation service which requires translating .po file (ruby gettext gem). Spent hours to understand the rake tasks it provides and looked for methods to extract all String inside .po file. Finally found the parser and the method to do my job:


require 'gettext/tools/poparser'
require 'gettext/tools/rmsgmerge'

parser = GetText::PoParser.new
result = parser.parse_file("...../my_rails_project/po/en/text_domain.po", GetText::RMsgMerge::PoData.new, false)

the object representing the data structure is assigned to result.


In case you are also extending gettext library, check the gettext/tools directory. Most of the useful methods are located there.

1 comment:

  1. Hello! If you are working on translating po files, I suggest to try a software localization management tool like POEditor that can automate and improve your workflow.

    ReplyDelete