0

I know that PO / MO files are meant to be used for small strings like button names, labels, etc. Not long text like an About page, etc.

But lately I am encountering a lot of situations that are in the middle. For example, a two sentence call to action. Or a short paragraph.

Is there best practice or "rule of thumb" for when a string is too long to put in a PO file?

update

For "long" text I use partials and include the correct language version. My question is WHEN is it optimal to use one vs the other. I've heard that PO files are "inefficient" for "long" pieces of text. But what does that mean and when is it too "long"? Or is this not a concern?

emersonthis
  • 32,822
  • 59
  • 210
  • 375

1 Answers1

0

Use one entry for a self-contained chunk of text; e.g. a sentence as you say.

Two sentences that belong together and don't make sense without each other should be one entry. Why? Because otherwise the translator wouldn't have the context necessary to translate it well. Same goes for a short paragraph, e.g. explaining a setting: if it's inseparable in the code, it should be one entry.

If you encounter a situation where you have lots of long texts regularly (e.g. entire pages or paragraphs of pages), that's usually a sign that you are using an ill-fitting tool. Some people do it, using Gettext for entire articles, but you're better off having separate documents in such cases. But that doesn't seem to be the case here.

Václav Slavík
  • 6,445
  • 2
  • 28
  • 25
  • For "long" text I use partials and include the correct language version. My question is WHEN is it optimal to use one vs the other. I've heard that PO files are "inefficient" for "long" pieces of text. But what does that mean and when is it too "long"? Or is this not a concern? – emersonthis Feb 21 '15 at 21:52
  • @SDP Your question wasn’t about “when” is it “optimal”, but what the best practice is — which I answered. I don’t know what “optimal” could even mean here (wrt *what*?). The claim that a *text format* is somehow “inefficient” is nonsense, pay no attention to it. PO format is *ill-suited* for *free-form text*, regardless of length, because the larger context of free-form text is missing when stored as independent PO entries. And PO *software* (such as my Poedit) tends to have UI optimized for “normal” gettext use (UI strings), which makes using such *SW* with free-form text a pain. That’s all. – Václav Slavík Feb 22 '15 at 11:56
  • Are you saying there is absolutely zero performance overhead to consider? I've seen it mentioned many times that gettext "performs poorly on long strings". Is that true? If so, what is the cut-off? This is what I'm really trying to understand. – emersonthis Feb 22 '15 at 12:35
  • @SDP Err, you updated the question *after* I answered it (and I reacted to the changes in the comment). As for “performance”: you may talk about performance of the GNU gettext tools or performance of specific gettext *libraries* (of which there are *many*, so the “specific” bit is important), but of a file format? Not really. A sanely written library will use the embedded hash table and run in *O(strlen)* — but *fast*. You shouldn’t worry about performance unless you actually *see* some performance degradations — and with gettext, you really won’t. – Václav Slavík Feb 22 '15 at 16:10
  • So if the context dictates it, it is "ok" to put a page of text on the PO file without "breaking" anything? – emersonthis Feb 23 '15 at 14:56