NAME
Locale::Simple::PO2JSON - Convert a gettext PO file to the JSON data Locale::Simple reads in the browser
VERSION
version 0.200
SYNOPSIS
use Locale::Simple::PO2JSON qw( po2data data2json );
my $data = po2data('de.po');
my $json = data2json( po2data( 'de.po', domain => 'myapp' ), pretty => 1 );
DESCRIPTION
Reads a gettext PO file and produces the data structure the JavaScript side of Locale::Simple loads: a header hash under the empty key and one entry per translated message. Which entries are kept follows msgfmt: entries with an empty first translation, fuzzy entries (the header excepted) and obsolete entries are left out.
po2data
my $data = po2data( $path, domain => $name );
Returns a hash reference. The empty key holds the header (values trimmed, plus lang from Language); every other key is the msgid, or "$msgctxt\x04$msgid" with a context, and holds an array reference [ $msgid_plural_or_undef, @msgstr ]. With domain the whole structure is nested under that name. A file without Plural-Forms header that contains plural entries produces one warning; the entries keep the forms they have. Dies with Cannot read PO file PATH: REASON or PATH line N: REASON.
data2json
my $json = data2json( $data, pretty => 1 );
Encodes UTF-8 JSON with sorted keys and without trailing newline.
SUPPORT
Issues
Please report bugs and feature requests at https://github.com/Getty/locale-simple/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.
This is free software, licensed under:
The MIT (X11) License