This is a Ruby library for the GNU gettext PO files. This is a C binding of the libgettextpo library, which is provided by the GNU gettext package. The API of this gem is designed to promote Ruby's idiomatic coding style while paying attensiton to memory safety. Currently this supports both CRuby and mruby.
Prerequisites: libgettextpo library (mruby: version 1.0 or later).
On Linux and similar systems, you should be able to install it as a
distribution package on most platforms. For example, on Ubuntu it was
as follows (2026-03-07T15:48:13+09:00):
apt search libgettextpo
# Sorting... Done
# Full Text Search... Done
# libgettextpo-dev/noble 0.21-14ubuntu2 amd64 <----- This one!
# process PO files - static libraries and headers
#
# libgettextpo0/noble 0.21-14ubuntu2 amd64
# process PO files - shared libraryFor CRuby:
-
Install the gem and add to the application's
Gemfileby executing:bundle add gettextpo
-
If Bundler is not being used to manage dependencies, install the gem by executing:
gem install gettextpo
For mruby, modify build_config.rb as you like, set MRUBY_SRC to
mruby source repository, and run ./bin/compile or ./bin/test.
Say we have a PO file like:
msgid "msgid1"
msgstr "msgstr1"at po_path, then,
require "gettextpo"
GettextPO::File.read(po_path).message_iterator.each do |message|
pp({ source: message.msgid, translation: message.msgstr })
#=> {source: "msgid1", translation: "msgstr1"}
endPlease refer to the API documentation and test cases for details. The mruby version has same API.
After checking out the repo, run bin/setup to install
dependencies. Then, run rake test to run the tests. You can also run
bin/console for an interactive prompt that will allow you to
experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in
version.rb, and then run bundle exec rake release, which will
create a git tag for the version, push git commits and the created
tag, and push the .gem file to rubygems.org.
File structure:
bin : script ifles
build_config.rb : for mruby
* build_config.rb.lock
CHANGELOG.md
COPYING
* doc : generated by RDoc from CRuby sources
ext : for CRuby
Gemfile : for CRuby
gettextpo.gemspec : for CRuby
include : for mruby
lib : for CRuby
mrbgem.rake : for mruby
mrblib : for mruby
* pkg : generated by RubyGem
Rakefile : for CRuby
README.md
- sample.rb : for debug purpose especially with GDB
sig : for CRuby
src : for mruby
test : common test cases for both CRuby and mruby
test.cruby : CRuby specific tests
* tmp
- .env
.env.example
.envrc : Direnv config
.clang-format
.dir-locals.el : Emacs config
.gitignore
* generated files
- ignored by version control
Bug reports and pull requests are welcome on GitHub.
Other links:
Copyright (C) 2026 gemmaro
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.