Missing head-entry breaks projet push

Issue #3 resolved
John Lindahl created an issue

I am using react-intl-po to convert react-intl message definitions to and from .po(t) files.

The problem I am currently facing with using zanata-js to be able to push these po-files is that react-intl-po does not add the head entry to the .pot-files.

Due to this zanata-js breaks here and here because the code just assumes everything to be fine and dandy.

My suggestion is to add the following "protection" to the code:

    ext.entries = Object.keys(po.headers || []).map((k) => { // <- defaulting to empty headers
      return {key: k, value: po.headers[k]};
    });
    if (po.translations && po.translations[''] && po.translations[''][''] && po.translations[''][''].comments) // <- Checking the entire depth of the object
      ext.comment = po.translations[''][''].comments.translator;

An alternative approach if you do not want to support "invalid" .pot files is to throw a more informative error-message telling the user that the head entry is missing instead of cryptic TypeErrors.

Comments (2)

  1. Log in to comment