Detect the language of a string or list of strings.

        See https://cloud.google.com/translate/docs/detecting-language

        :type values: str or list
        :param values: String or list of strings that will have
                       language detected.

        :rtype: dict or list
        :returns: A list of dictionaries for each queried value. Each
                  dictionary typically contains three keys

                  * ``confidence``: The confidence in language detection, a
                    float between 0 and 1.
                  * ``input``: The corresponding input value.
                  * ``language``: The detected language (as an ISO 639-1
                    language code).

                  though the key ``confidence`` may not always be present.

                  If only a single value is passed, then only a single
                  dictionary will be returned.
        :raises: :class:`ValueError <exceptions.ValueError>` if the number of
                 detections is not equal to the number of values.
                 :class:`ValueError <exceptions.ValueError>` if a value
                 produces a list of detections with 0 or multiple results
                 in it.

def detect_language(self, values):
        """Detect the language of a string or list of strings.

        See https://cloud.google.com/translate/docs/detecting-language

        :type values: str or list
        :param values: String or list of strings that will have
                       language detected.

        :rtype: dict or list
        :returns: A list of dictionaries for each queried value. Each
                  dictionary typically contains three keys

                  * ``confidence``: The confidence in language detection, a
                    float between 0 and 1.
                  * ``input``: The corresponding input value.
                  * ``language``: The detected language (as an ISO 639-1
                    language code).

                  though the key ``confidence`` may not always be present.

                  If only a single value is passed, then only a single
                  dictionary will be returned.
        :raises: :class:`ValueError <exceptions.ValueError>` if the number of
                 detections is not equal to the number of values.
                 :class:`ValueError <exceptions.ValueError>` if a value
                 produces a list of detections with 0 or multiple results
                 in it.
        """
        single_value = False
        if isinstance(values, six.string_types):
            single_value = True
            values = [values]

        data = {"q": values}

        response = self._connection.api_request(
            method="POST", path="/detect", data=data
        )

        detections = response.get("data", {}).get("detections", ())

        if len(values) != len(detections):
            raise ValueError(
                "Expected same number of values and detections", values, detections
            )

        for index, value in enumerate(values):
            # Empirically, even clearly ambiguous text like "no" only returns
            # a single detection, so we replace the list of detections with
            # the single detection contained.
            if len(detections[index]) == 1:
                detections[index] = detections[index][0]
            else:
                message = (
                    "Expected a single detection per value, API " "returned %d"
                ) % (len(detections[index]),)
                raise ValueError(message, value, detections[index])

            detections[index]["input"] = value
            # The ``isReliable`` field is deprecated.
            detections[index].pop("isReliable", None)

        if single_value:
            return detections[0]
        else:
            return detections