import codecs


def read_file(path, uncomment_moz_langpack=False):
    """Read the resource at the given path."""
    with codecs.open(path, "r", "utf-8") as f:
        # .inc files have a special commented-out entity called
        # MOZ_LANGPACK_CONTRIBUTORS. We optionally un-comment it before
        # parsing so locales can translate it.
        if uncomment_moz_langpack:
            lines = []
            for line in f:
                if line.startswith("# #define MOZ_LANGPACK_CONTRIBUTORS"):
                    line = line[2:]
                lines.append(line)
            content = "".join(lines)
        else:
            content = f.read()

    return content