Giter Club home page Giter Club logo

get_pomo's Introduction

This project is no longer maintained.

If you only need to handle PO files you might want to check out PoParser

If you only need the raw PO data parsed to a ruby hash check out PoParser's core simple_po_parser

get_pomo

A simple and extendable .mo and .po file parser/generator.

Advanteges over original mo / po-parser:

  • simple architecture + easy to extend/modify
  • emtpy msgstr translations are read
  • comments are included
  • obsolete translations are included if enabled
  • fuzzy can be set/unset
  • references of non unique translations can be merged
  • multiple translations can be combined in a new po file(with comments and fuzzy and ...)
  • po files can be written from any kind of input
  • easy mo-file handling/merging
  • po/mo file handling is identical, if you know one, you know both

Setup

sudo gem install get_pomo

Static interface

    #parse po files, first with obsolete messages second without
    translations = GetPomo::PoFile.parse(File.read('xxx.po'), :parse_obsoletes => true) + GetPomo::PoFile.parse(File.read('yyy.po'))

    #and use the data...
    msgids = translations.reject{|t|t.plural? or t.fuzzy? or t.obsolete?}.map(&:msgid)

    #or write a new po file (unique by msgid, with merged references for non uniques)...
    File.open('xxx.po','w){|f|f.print(GetPomo::PoFile.to_text(translations, :merge => true))}

Instance interface

p = GetPomo::PoFile.new
p.add_translations_from_text(File.read('...'))
...
p.translations
p.to_text

GetPomo::MoFile behaves identical.

TODO

  • extracting of version/pluralisation_rule/plurals/translator... (from msgid "")
  • the vendor/mofile is really complex, maybe it can be refactored (also some parts are not needed)

Authors

Michael Grosser
[email protected]
License: MIT
Build Status

get_pomo's People

Contributors

dfherr avatar e-tobi avatar fotanus avatar grosser avatar haeky avatar neohunter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

get_pomo's Issues

invalid multibyte character

when I run deploy and assets are precompiled:

bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"

I get this error:

.../gems/get_pomo-0.6.3/lib/get_pomo/po_file.rb:25: invalid multibyte character: /\xEF\xBB\xBF/

Escaping slashes

Escaping slashes has some weird behaviour right now.

Imho it should escape slashes if these slashes were used to escape content in the original string. That means

 \" should become \\\"
but
\n should escape to \\n

It somewhat seems to double escape slashes in the comments, but doesn't in the msgstr.

Example:

#, fuzzy
#| msgid "Weird Bug\" :"
msgid "Weirder Bug"
msgstr "Komischer Bug\" :"

(with fuzzy msgstr "Komischer Bug" :" obviously)
Will output to:

Komischer Bug" :       # msgstr
Weird Bug\" :          # fuzzy msgid (#| msgid)

So imho comment output works correctly, but msgstr (and probably msgid) are not escaping the slash before the quote and are therefor generating invalid output if escaped characters like quotes are in the original string.

Lost messages when contexts are used

I have just discovered that this project is no longer maintained. I'll therefore work to migrate to the recommended system.

However, for the record, when there are two identical msgids, one with a context and the other without, the one without context is ignored.

It is unique_translations that drops the missing translations.

mk = ->(ctx, id, str) {
    res = GetPomo::Translation.new
    res.msgctxt = ctx if ctx
    res.msgid = id
    res.msgstr = str
    res
}

translations = [
    mk.(nil, 'Amount', 'Montant'),
    mk.('Invoice', 'Amount', 'Montant'),
]
GetPomo.unique_translations(translations)

=>

[#<GetPomo::Translation:0x00007ffb57cac218
  @msgctxt="Invoice",
  @msgid="Amount",
  @msgstr="Montant">]

obsolete messages

ignores obsolete messages (#~) as they do not have msgstr and msgid and are just comments.

parse => to_text shouldn't change the file

The parser does not remember linebreakes of multiline msgid's and msgstr's.

well this is a rather big one I didn't really thought about changing, as I use my own methods for writing the method and not to_text. In the process of refactoring I would like to do anything that is about parsing/writing with the gem.

It does not violate the gettext rules to concatenate multiline msgid's or msgstr's, but it causes for example the header to be in one line, which is not desireable.

To keep the multiline presentation while parsing, msgstr and msgid must be represented as a list (array) internally.
I could do this the harsh way which would require a version jump and breaking any existing use of the gem, or the soft way by adding helper methods for msgid/msgstr which return the concatenated version, but keeping lists for their content.

On a plus the second way wouldn't change how the mo/po interface works and wouldn't break existing code. The drawback would be performance and messy logic.

What do you think @grosser ?

faster parser

@grosser just wanted to let you know that I worte a faster parser with more detailed output and just open sourced it today https://github.com/experteer/simple_po_parser

It's actually meant as the new core for this project https://github.com/arashm/PoParser

It benchmarks about twice as fast as this parser and has a more detailed output. (It basically splits the output into a hash where every little fragment specified by the GNU gettext specification has it's own key. My private project using the get_pomo gem since 2013 actually parsed this stuff in a second parsing step from the get_pomo output ๐Ÿ˜ƒ)

I'm not sure if it makes sense to update this old project to use the other projects as new cores and add the unique features of this project as another layer on top, but at least I wanted to let you know it's out there :D

msgctxt multiline throws error

I've a PO file with:

msgctxt "Not
really."
msgid "I have\n%d cat."
msgstr ""

This is raining an GetPomo::InvalidString error.

I'm not sure if this is a valid po format, or each line should end in "

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.