imcrazytwkr / po_parser

A Crystal Po parser based on SimplePoParser gem by Experteer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PoParser

Build Status License

A Crystal Po parser based on Simple Po Parser gem by Experteer. PO files are translation files generated by GNU/Gettext. This Shard should be compatible with GNU Po file format. Bugs can be reported to the issue tracker.

Installation

Add this to your application's shard.yml:

dependencies:
  simple_po_parser:
    github: imcrazytwkr/po_parser

Usage

The parser can be used in two ways:

require "po_parser"

PoParser.parse_file(file_path) # parses a Po file and returns array of Message objects
PoParser.parse_message(message) # parses a single Po message and returns a Message object

Message object structure

Message object represents a message from a Po file. You can access every property of the message using it. However, instead of shortened keys in the file itself, the object uses full notations to improve code readability. You can find the table below to see which method corresponds to specific message in a Po file.

Object method Po message key
message_context msgctxt
message_id msgid
message msgstr
message_id_plural msgid_plural
message_plural[N] msgstr[N]

The methods above also exist in "previous" (previous_{{method_name}}) form. These work according to Po file specification. Here's the list of other methods for accessing comment types allowed by the Po file format:

  • translator_comment
  • extracted_comment
  • reference
  • flag
  • obsolete

When accessing any of previously mentioned methods, you can add a question mark to method name to check if the key was set in the original file instead of relying on .not_nil! and exception handling. Additionally, every Message object has service .empty? method that checks whether the message is empty (also works for checking if the message was parsed in the first place; it is mostly use internally to cache parsing result within instance variable of Parser class).

Roadmap

  • Add class for Po file header and header parsing feature into Tokenizer class
  • Make Tokenizer return Dictionary (working title) class that contains file header and all of its messages
  • Potentially add statistical methods to Dictionary class (need suggestions and potential use cases for this one)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

About

A Crystal Po parser based on SimplePoParser gem by Experteer

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Crystal 100.0%