Pokeapi: flavor_text_entries (description) hasn't a fix index for each language

Created on 25 May 2020  路  4Comments  路  Source: PokeAPI/pokeapi

Hi,
I'm having a lot of fun learning Javascript using Pok茅api, so first thank you for that !
I've created a pokedex (in french), and i'm using [flavor_text_entries] to get the pokemon's description. So in https://pokeapi.co/api/v2/pokemon-species/1 I'm getting [flavor_text_entries][5][flavor_text] to have the french description of the pokemon. In this case (for bulbasaur) I indeed have the french description. But for Starmie for example (id 121), [flavor_text_entries][5][flavor_text] return the description in German.
So I've tested on several pokemon, and it happens that some have a french description and some have a german one. How can I fix that to always have the french one ? Cheers !

All 4 comments

As a workaround loop through the flavor text entries and just select those which have ['language']['name']=='fr'
That's what I did.

Oh right didn't think about it, thank you !

Actually there are many inconsistencies in the data and you just need a little programming to find your way around them.

flavor_text doe not guarantee that text for a certain language will always be at the same index of the list.
You should always check the language name field for the language you want, as @HybridShivam explained.

You can check the documentation for more information.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cmmartti picture cmmartti  路  4Comments

neverendingqs picture neverendingqs  路  5Comments

mjhayes412 picture mjhayes412  路  7Comments

nnguy152 picture nnguy152  路  5Comments

phalt picture phalt  路  8Comments