csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
791 stars 175 forks source link

Language support doesn't work #251

Closed TuxSeb closed 6 years ago

TuxSeb commented 6 years ago

I have an issue when i'm trying to use French on pyowm, here's the the code:

import pyowm
owm = pyowm.OWM(API_key='MY_API_KEY', language='fr')
observation = owm.weather_at_place('London,GB')
w = observation.get_weather()
print w

and here's the output:

<pyowm.webapi25.weather.Weather - reference time=2018-05-29 17:50:00+00, status=Haze>

What Pyowm is supposed to do when we use an other language ? shouldn't it print the French word for haze ?

pyowm version: 2.8.0

thanks for your help

csparpa commented 6 years ago

Hi @TuxSeb thanks for pointing this out

I've checked out and it looks like everything works fine. When you call print w the weather's status property is printed but unfortunately that string is not translated by the OWM API

The reason is mentioned here: https://openweathermap.org/current :

image

The NOTE says that only the description JSON field is returned in translation (in French in your case). That JSON field is then mapped by PyOWM onto thedetailed_status field of class Weather

Just to counter check, please execute:

import pyowm
owm = pyowm.OWM(API_key='MY_API_KEY', language='fr')
observation = owm.weather_at_place('London,GB')
w = observation.get_weather()
print w.get_status()
print w.get_detailed_status()

and you should get something like:

Haze
brume sèche

depending on the actual weather in London now.

But I do see your point: if one wants to print weather status in a certain language, why should that info be printed in English?

I will augment the Weather.__repr__ method with the detailed status so that the translated string is printed out

TuxSeb commented 6 years ago

Ok, thanks you !

csparpa commented 6 years ago

Fixed with https://github.com/csparpa/pyowm/commit/cceeb1a1fb6e64aa29c670e4dc92022a7f907c11