Skip to content

Commit

Permalink
Exposed list of OWM supported languages
Browse files Browse the repository at this point in the history
  • Loading branch information
csparpa committed Sep 23, 2020
1 parent f9f2f7a commit eb1f943
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Code
* [lardconcepts](https://github.com/lardconcepts)
* [liato](https://github.com/liato)
* [LukasBoersma](https://github.com/LukasBoersma)
* [Misiu](https://github.com/Misiu)
* [Noid](https://github.com/n0id)
* [titilambert](https://github.com/titilambert)
* [txemi](https://github.com/txemi)
Expand Down
51 changes: 51 additions & 0 deletions pyowm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,54 @@
STATIONS_API_VERSION = (3, 0, 0)
UVINDEX_API_VERSION = (3, 0, 0)
WEATHER_API_VERSION = (2, 5, 0)
LANGUAGES = [
"af",
"al",
"ar",
"az",
"bg",
"ca",
"cz",
"da",
"de",
"el",
"en",
"es",
"eu",
"fa",
"fi",
"fr",
"gl",
"he",
"hi",
"hr",
"hu",
"id",
"it",
"ja",
"kr",
"la",
"lt",
"mk",
"nl",
"no",
"pl",
"pt",
"pt_br",
"ro",
"ru",
"se",
"sk",
"sl",
"sp",
"sr",
"sv",
"th",
"tr",
"ua",
"uk",
"vi",
"zh_cn",
"zh_tw",
"zu",
]
10 changes: 10 additions & 0 deletions pyowm/owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def version(self):
"""
return constants.PYOWM_VERSION

@property
def supported_languages(self):
"""
Returns the languages that the OWM API supports
:return: `list` of `str`
"""
return constants.LANGUAGES

def agro_manager(self):
"""
Gives a `pyowm.agro10.agro_manager.AgroManager` instance that can be used to read/write data from the
Expand Down
13 changes: 10 additions & 3 deletions sphinx/v3/code-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ owm = OWM('your-api-key', config_dict)
```

### Language setting
English is the default - but you can change it
Check out [https://openweathermap.org/current](https://openweathermap.org/current) for the complete list of supported languages
The list of supported languages is given by:
```python
from pyowm.owm import OWM
owm = OWM('your-api-key')
owm.supported_languages
```
Check out [https://openweathermap.org/current](https://openweathermap.org/current) for reference on supported languages

English is the default language on the OWM API - but you can change it:

```python
from pyowm.owm import OWM
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language'] = 'pt' # your language here
config_dict['language'] = 'pt' # your language here, eg. Portuguese
owm = OWM('your-api-key', config_dict)
```

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def test_properties(self):
version = self.__test_instance.version
self.assertIsInstance(version, tuple)

languages = self.__test_instance.supported_languages
self.assertIsInstance(languages, list)
self.assertTrue(all([isinstance(lang, str) for lang in languages]))

config = self.__test_instance.configuration
self.assertIsInstance(config, dict)

Expand Down

0 comments on commit eb1f943

Please sign in to comment.