smhg / gettext-parser

Parse and compile gettext po and mo files, nothing more, nothing less
MIT License
158 stars 44 forks source link

An option to disable automatic msgstr folding #32

Closed SleepWalker closed 6 years ago

SleepWalker commented 7 years ago

Hi @smhg

what do you think about making automatic msgstr folding as an optional feature?

So that we can do something like the following:

po.compile(str, {
    autoFolding: false,
    maxLen: 123
});
smhg commented 7 years ago

@SleepWalker, my first thoughts:

SleepWalker commented 6 years ago

Sorry for my delayed answer.

I can't say what other libraries provide. In my case I've used gettext-parser (thank you for this great lib :+1: ) for import/export tool for project that is written on php. The lib used there interpreted the first, empty line of folded translation as  , which is not exactly what I needed.

I've solved this problem by monkey-patching your lib (because I can't touch the code of gettext on php side), but I've thought, that it would be great feature to be able to choose formatting style.

All project have their own style guides and when you migrate to the tool, that dictates it's own style, you will have huge diffs. Of coarse this is not so critical, because this is just po files. So if you think, that such features is too much for gettext-libraries, then please close this issue.

Isn't this easily accomplished on a per-use-case basis by pulling in a folding library and wrapping your data object with it (before passing it to po.compile)?

po.compile will force-fold everything. So I can't see how to e.g. disable folding or fold at the length greater than 76 without monkey-patching your lib. But, as I said, I do not insist on the implementation of this feature. I've solved my problem already.

smhg commented 6 years ago

I think you have a good argument. Let's add an options parameter to po.compile with foldLength as the only option for now. The default will be 76, with 0 (or anything not > 0, like false) resulting in no folding.