有没有办法翻译 API 信息(alexa 开发者控制台,-pip 安装不起作用)

Is there a way to translate API Information (alexa developer console, -pip install dont work)

我目前有一个 API 我的天气意图,但我需要翻译主要信息,如雪、太阳、雨等。有没有人知道我如何在进入 speak_output 之前翻译它们?

class wetterHandler(AbstractRequestHandler):
    """Handler for Get Weather Intent."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return ask_utils.is_intent_name("wetter")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        api_url= "http://api.openweathermap.org/data/2.5/weather?q=München&appid=b9ad6b1c8e80f623ff23a53cdd8832a9&units=metric"
        json_data = requests.get(api_url).json()
        weather_json = json_data['weather'][0]['main']
        temp_json = round(json_data['main']['temp'] )
        city = "München"
        speak_output = "The weather is {} and temperature is {} °C in {}. " .format(weather_json, temp_json, city)
        reprompt = "Want to try again? Or you can say cancel to quit."
        handler_input.response_builder
        
        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(reprompt)
                .response
        )

已解决: 获得 API 的所有可能 returns 并在代码打印 speakout 之前放一个简单的 if:

def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        api_url= "http://api.openweathermap.org/data/2.5/weather?q=München&appid=b9ad6b1c8e80f623ff23a53cdd8832a9&units=metric"
        json_data = requests.get(api_url).json()
        weather_json = json_data['weather'][0]['main']
        if weather_json == "Snow":
            weather_json = "am Schneien"
        if weather_json == "Rain":
            weather_json = "Regnerisch"
        if weather_json == "Clouds":
            weather_json = "Bewölkt"
        if weather_json == "Sun":
            weather_json = "Sonnig"
        if weather_json == "Wind":
            weather_json = "Windig"
        temp_json = round(json_data['main']['temp'] )
        city = "München"
        speak_output = "Aktuell ist es {} und die Temperatur beträgt {} °C in {}. Wie sollen wir fortfahren? " .format(weather_json, temp_json, city)
        reprompt = "Möchtest du nochmal das Wetter abfragen?"
        handler_input.response_builder
        
        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(reprompt)
                .response
        )

您可以简单地 specify the language 在您的请求中 URL 像这样:

http://api.openweathermap.org/data/2.5/weather?id=524901&appid={API key}&lang={lang}

因此,要获取德语天气信息,您可以向以下地址发出请求:

http://api.openweathermap.org/data/2.5/weather?q=München&appid=b9ad6b1c8e80f623ff23a53cdd8832a9&units=metric&lang=de