Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>Call <code>PoParser.parsePo("po file content")</code>. The result is a list of <code>Translation</code>.</p> <p>I have made this code into a library (can be used by any JVM languages, including Java, of course!): <a href="https://github.com/ngocdaothanh/scaposer" rel="noreferrer">https://github.com/ngocdaothanh/scaposer</a></p> <pre><code>import scala.util.parsing.combinator.JavaTokenParsers trait Translation case class SingularTranslation( msgctxto: Option[String], msgid: String, msgstr: String) extends Translation case class PluralTranslation( msgctxto: Option[String], msgid: String, msgidPlural: String, msgstrNs: Map[Int, String]) extends Translation // http://www.gnu.org/software/hello/manual/gettext/PO-Files.html object PoParser extends JavaTokenParsers { // Removes the first and last quote (") character of strings // and concats them. private def unquoted(quoteds: List[String]): String = quoteds.foldLeft("") { (acc, quoted) =&gt; acc + quoted.substring(1, quoted.length - 1) } // Scala regex is single line by default private def comment = rep(regex("^#.*".r)) private def msgctxt = "msgctxt" ~ rep(stringLiteral) ^^ { case _ ~ quoteds =&gt; unquoted(quoteds) } private def msgid = "msgid" ~ rep(stringLiteral) ^^ { case _ ~ quoteds =&gt; unquoted(quoteds) } private def msgidPlural = "msgid_plural" ~ rep(stringLiteral) ^^ { case _ ~ quoteds =&gt; unquoted(quoteds) } private def msgstr = "msgstr" ~ rep(stringLiteral) ^^ { case _ ~ quoteds =&gt; unquoted(quoteds) } private def msgstrN = "msgstr[" ~ wholeNumber ~ "]" ~ rep(stringLiteral) ^^ { case _ ~ number ~ _ ~ quoteds =&gt; (number.toInt, unquoted(quoteds)) } private def singular = (opt(comment) ~ opt(msgctxt) ~ opt(comment) ~ msgid ~ opt(comment) ~ msgstr ~ opt(comment)) ^^ { case _ ~ ctxto ~ _ ~ id ~ _ ~ s ~ _ =&gt; SingularTranslation(ctxto, id, s) } private def plural = (opt(comment) ~ opt(msgctxt) ~ opt(comment) ~ msgid ~ opt(comment) ~ msgidPlural ~ opt(comment) ~ rep(msgstrN) ~ opt(comment)) ^^ { case _ ~ ctxto ~ _ ~ id ~ _ ~ idp ~ _ ~ tuple2s ~ _ =&gt; PluralTranslation(ctxto, id, idp, tuple2s.toMap) } private def exp = rep(singular | plural) def parsePo(po: String): List[Translation] = { val parseRet = parseAll(exp, po) if (parseRet.successful) parseRet.get else Nil } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload