# Buggy code
def _set_mime_headers(self, headers):
    for name, value in headers:
        name = name.lower()
        if name == "project-id-version":
            parts = value.split(" ")
            self.project = " ".join(parts[:-1])
            self.version = parts[-1]
        elif name == "report-msgid-bugs-to":
            self.msgid_bugs_address = value
        elif name == "last-translator":
            self.last_translator = value
        elif name == "language":
            value = value.replace("-", "_")
            self.locale = Locale.parse(value)
        elif name == "language-team":
            self.language_team = value
        elif name == "content-type":
            mimetype, params = parse_header(value)
            if "charset" in params:
                self.charset = params["charset"].lower()
        elif name == "plural-forms":
            _, params = parse_header(" ;" + value)
            self._num_plurals = int(params.get("nplurals", 2))
            self._plural_expr = params.get("plural", "(n != 1)")
        elif name == "pot-creation-date":
            self.creation_date = _parse_datetime_header(value)
        elif name == "po-revision-date":
            # Keep the value if it's not the default one
            if "YEAR" not in value:
                self.revision_date = _parse_datetime_header(value)


# Traceback (babel.core.UnknownLocaleError)
Traceback (most recent call last):
File "/usr/local/bin/pybabel", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 908, in main
return CommandLineInterface().run(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 832, in run
return cmdinst.run()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 182, in run
self._run_domain(domain)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/frontend.py", line 221, in _run_domain
catalog = read_po(infile, locale)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 331, in read_po
parser.parse(fileobj)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 265, in parse
self._process_comment(line)
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 224, in _process_comment
self._finish_current_message()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 164, in _finish_current_message
self._add_message()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/pofile.py", line 158, in _add_message
self.catalog[msgid] = message
File "/usr/local/lib/python3.5/dist-packages/babel/messages/catalog.py", line 596, in __setitem__
self.mime_headers = _parse_header(message.string).items()
File "/usr/local/lib/python3.5/dist-packages/babel/messages/catalog.py", line 399, in _set_mime_headers
self.locale = Locale.parse(value)
File "/usr/local/lib/python3.5/dist-packages/babel/core.py", line 331, in parse
raise UnknownLocaleError(input_id)
babel.core.UnknownLocaleError: unknown locale 'sr_SP'

# Fixed code
def _set_mime_headers(self, headers):
    for name, value in headers:
        name = name.lower()
        if name == "project-id-version":
            parts = value.split(" ")
            self.project = " ".join(parts[:-1])
            self.version = parts[-1]
        elif name == "report-msgid-bugs-to":
            self.msgid_bugs_address = value
        elif name == "last-translator":
            self.last_translator = value
        elif name == "language":
            value = value.replace("-", "_")
            self._set_locale(value)
        elif name == "language-team":
            self.language_team = value
        elif name == "content-type":
            mimetype, params = parse_header(value)
            if "charset" in params:
                self.charset = params["charset"].lower()
        elif name == "plural-forms":
            _, params = parse_header(" ;" + value)
            self._num_plurals = int(params.get("nplurals", 2))
            self._plural_expr = params.get("plural", "(n != 1)")
        elif name == "pot-creation-date":
            self.creation_date = _parse_datetime_header(value)
        elif name == "po-revision-date":
            # Keep the value if it's not the default one
            if "YEAR" not in value:
                self.revision_date = _parse_datetime_header(value)