Repository: lingui/js-lingui (ts)

Issue:
Built PO file contains header with incorrect letter case
**Describe the bug**
Extracting PO file generates a file containing the header "Mime-Version: 1.0\n".

**Expected behavior**
Extracting PO file should generate a file containing the header "MIME-Version: 1.0\n" (note the difference in letter case).

**Additional context**

- jsLingui version ``lingui --version``: 3.9.0
- Babel version ``npm list @babel/core`` 7.14.3

"MIME-Version: 1.0\n" seems to be the correct case (http://pology.nedohodnik.net/doc/user/en_US/ch-poformat.html).

When opening a file generated by lingui with Poedit, a new header "MIME-Version: 1.0\n" is written in addition to the one already in the file ("Mime-Version: 1.0\n"). That creates unnecessary diff in git.

Pull request:
fix: Use correct case for PO file header MIME-Version
Fix #1071

Patch:
diff --git a/examples/create-react-app/src/locales/en/messages.po b/examples/create-react-app/src/locales/en/messages.po
index f8c31c25..2ed3e8f4 100644
--- a/examples/create-react-app/src/locales/en/messages.po
+++ b/examples/create-react-app/src/locales/en/messages.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2020-10-20 12:51+0200\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/examples/js/src/locale/cs/messages.po b/examples/js/src/locale/cs/messages.po
index 67fac6c9..2b0f8f61 100644
--- a/examples/js/src/locale/cs/messages.po
+++ b/examples/js/src/locale/cs/messages.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-09-09 19:21+0200\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/examples/js/src/locale/en/messages.po b/examples/js/src/locale/en/messages.po
index 1f57e72b..7b450657 100644
--- a/examples/js/src/locale/en/messages.po
+++ b/examples/js/src/locale/en/messages.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-09-09 19:21+0200\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/examples/next-js/locale/cs/messages.po b/examples/next-js/locale/cs/messages.po
index ed6e3b64..e28e84c5 100644
--- a/examples/next-js/locale/cs/messages.po
+++ b/examples/next-js/locale/cs/messages.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2020-04-04 12:09+0200\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/examples/next-js/locale/en/messages.po b/examples/next-js/locale/en/messages.po
index 0cdb0acc..af360abc 100644
--- a/examples/next-js/locale/en/messages.po
+++ b/examples/next-js/locale/en/messages.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2020-04-04 13:38+0200\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/packages/cli/src/api/formats/fixtures/messages.po b/packages/cli/src/api/formats/fixtures/messages.po
index 593d59a0..3bb873ca 100644
--- a/packages/cli/src/api/formats/fixtures/messages.po
+++ b/packages/cli/src/api/formats/fixtures/messages.po
@@ -6,7 +6,7 @@ msgstr ""
 "Report-Msgid-Bugs-To: Daniel Krejčí <fredy.c@seznam.cz>\n"
 "Last-Translator: Tomáš Ehrlich <tomas.ehrlich@gmail.com>\n"
 "Language-Team: jsLingui\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "Language: en\n"
diff --git a/packages/cli/src/api/formats/fixtures/messages_plural.po b/packages/cli/src/api/formats/fixtures/messages_plural.po
index 4431962c..b78f5d6a 100644
--- a/packages/cli/src/api/formats/fixtures/messages_plural.po
+++ b/packages/cli/src/api/formats/fixtures/messages_plural.po
@@ -1,7 +1,7 @@
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-08-27 10:00+0000\n"
-"Mime-Version: 1.0\n"
+"MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 "X-Generator: @lingui/cli\n"
diff --git a/packages/cli/src/api/formats/index.ts b/packages/cli/src/api/formats/index.ts
index 380668ac..02001550 100644
--- a/packages/cli/src/api/formats/index.ts
+++ b/packages/cli/src/api/formats/index.ts
@@ -17,6 +17,7 @@ const formats: Record<CatalogFormat, CatalogFormatter> = {
 
 type CatalogFormatOptionsInternal = {
   locale: string
+  disableSelectWarning?: boolean
 } & CatalogFormatOptions
 
 export type CatalogFormatter = {
diff --git a/packages/cli/src/api/formats/po-gettext.ts b/packages/cli/src/api/formats/po-gettext.ts
index 327393bb..2fc75906 100644
--- a/packages/cli/src/api/formats/po-gettext.ts
+++ b/packages/cli/src/api/formats/po-gettext.ts
@@ -16,7 +16,7 @@ type POItemType = InstanceType<typeof PO.Item>
 function getCreateHeaders(language = "no") {
   return {
     "POT-Creation-Date": formatDate(new Date(), "yyyy-MM-dd HH:mmxxxx"),
-    "Mime-Version": "1.0",
+    "MIME-Version": "1.0",
     "Content-Type": "text/plain; charset=utf-8",
     "Content-Transfer-Encoding": "8bit",
     "X-Generator": "@lingui/cli",
@@ -62,9 +62,13 @@ const serialize = (items: CatalogType, options) =>
       // The extractedComments array may be modified in this method, so create a new array with the message's elements.
       // Destructuring `undefined` is forbidden, so fallback to `[]` if the message has no extracted comments.
       item.extractedComments = [...(message.extractedComments ?? [])]
-
-      if (options.origins) {
-        item.references = message.origin ? message.origin.map(joinOrigin) : []
+      
+      if (options.origins !== false) {
+        if (message.origin && options.lineNumbers === false) {
+          item.references = message.origin.map(msg => msg.slice(0, -1)).map(joinOrigin)
+        } else {
+          item.references = message.origin ? message.origin.map(joinOrigin) : []
+        }
       }
 
       // @ts-ignore: Figure out how to set this flag
diff --git a/packages/cli/src/api/formats/po.ts b/packages/cli/src/api/formats/po.ts
index 9794af5c..914cb1ee 100644
--- a/packages/cli/src/api/formats/po.ts
+++ b/packages/cli/src/api/formats/po.ts
@@ -9,7 +9,7 @@ import { CatalogFormatter } from "."
 
 const getCreateHeaders = (language = "no") => ({
   "POT-Creation-Date": formatDate(new Date(), "yyyy-MM-dd HH:mmxxxx"),
-  "Mime-Version": "1.0",
+  "MIME-Version": "1.0",
   "Content-Type": "text/plain; charset=utf-8",
   "Content-Transfer-Encoding": "8bit",
   "X-Generator": "@lingui/cli",


Test patch:
diff --git a/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap b/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap
index 0a813b56..dff78d61 100644
--- a/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap
+++ b/packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap
@@ -4,7 +4,7 @@ exports[`po-gettext format should convert ICU plural messages to gettext plurals
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-08-27 10:00+0000\\n"
-"Mime-Version: 1.0\\n"
+"MIME-Version: 1.0\\n"
 "Content-Type: text/plain; charset=utf-8\\n"
 "Content-Transfer-Encoding: 8bit\\n"
 "X-Generator: @lingui/cli\\n"
@@ -220,7 +220,7 @@ exports[`po-gettext format should write catalog in pofile format 1`] = `
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-08-27 10:00+0000\\n"
-"Mime-Version: 1.0\\n"
+"MIME-Version: 1.0\\n"
 "Content-Type: text/plain; charset=utf-8\\n"
 "Content-Transfer-Encoding: 8bit\\n"
 "X-Generator: @lingui/cli\\n"
diff --git a/packages/cli/src/api/formats/__snapshots__/po.test.ts.snap b/packages/cli/src/api/formats/__snapshots__/po.test.ts.snap
index 7d4c535c..1707f283 100644
--- a/packages/cli/src/api/formats/__snapshots__/po.test.ts.snap
+++ b/packages/cli/src/api/formats/__snapshots__/po.test.ts.snap
@@ -138,7 +138,7 @@ exports[`pofile format should write catalog in pofile format 1`] = `
 msgid ""
 msgstr ""
 "POT-Creation-Date: 2018-08-27 10:00+0000\\n"
-"Mime-Version: 1.0\\n"
+"MIME-Version: 1.0\\n"
 "Content-Type: text/plain; charset=utf-8\\n"
 "Content-Transfer-Encoding: 8bit\\n"
 "X-Generator: @lingui/cli\\n"
diff --git a/packages/cli/src/api/formats/po.test.ts b/packages/cli/src/api/formats/po.test.ts
index 2ff33a1a..9680e5c2 100644
--- a/packages/cli/src/api/formats/po.test.ts
+++ b/packages/cli/src/api/formats/po.test.ts
@@ -246,7 +246,7 @@ describe("pofile format", () => {
       msgid ""
       msgstr ""
       "POT-Creation-Date: ${formatDate(new Date(), "yyyy-MM-dd HH:mmxxxx")}\\n"
-      "Mime-Version: 1.0\\n"
+      "MIME-Version: 1.0\\n"
       "Content-Type: text/plain; charset=utf-8\\n"
       "Content-Transfer-Encoding: 8bit\\n"
       "X-Generator: @lingui/cli\\n"