what3words / w3w-node-wrapper

Node wrapper for the What3Words API
https://docs.what3words.com/api/v3/
MIT License
45 stars 10 forks source link

[IN-632] Improved language code validation #68

Closed chaddgrimm closed 8 months ago

chaddgrimm commented 8 months ago

The current implementation if a language code is valid is to check if the language code's length is more than two characters. This is incorrect since there are languages on our public API that uses locales, specifically for cyrillic and latin versions (i.e.: kk_la, kk_cy). It's better to validate the language code against the official list of languages that our api supports. To do this, we can call the /all-languages endpoint however it can become expensive if we do this every single time.

To get around this, a script to generate a typescript file with all of the supported languages is added to the precompile step so that it is ensured that every time we build and publish a version, our language list is up to date. This generated file is then referenced to a couple of functions that checks if a language is supported or not.