Does anyone know of a Java library that will let me parse .PO files? I simply want to create a Map of IDs and Values so I can load them into a database.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
According to Java gettext utilities Manual you may convert PO file to a ResourceBundle class using
msgfmt --java2
program and read it using java.util.ResourceBundle or gnu.gettext.GettextResource - I suppose it to be a most efficient way. Gettext-commons do exactly the same including intermediate process creation to call msgfmt because it is positioned as following:If you still want exactly a Java library then the only way I see is to write your own library for parsing this format i.e. rewrite msgfmt source code from C to Java language. But I'm not sure it will be faster than create process + run C program.
gettext-commons is the only one I've found while doing some research some time back.
.MO parser (not Java, but Scala), parses into Map : http://scalamagic.blogspot.com/2013/03/simple-gettext-parser.html , source: http://pastebin.com/csWx5Sbb
I searched the Internet and couldn't find an existing library, either. If you use Scala, it's quite easy to write a parser yourself, thanks to its parser combinator feature.
Call
PoParser.parsePo("po file content")
. The result is a list ofTranslation
.I have made this code into a library (can be used by any JVM languages, including Java, of course!): https://github.com/ngocdaothanh/scaposer
I have found some java classes to read and write po files : https://launchpad.net/po-parser
The tennera project on github contains an ANTLR-based parser for GNU Gettext PO/POT. I think it is used by Redhat for a web-based translation software.