I need to take an ISO 639-1 code such as en-GB
and convert it into an ISO 639-2 code such as eng
.
I have looked at the following libraries, but did not find a documented means to perform that transformation in any of them:
Have I missed something? That is - is this possible with any of these libraries?
You can use
pycountry
for what you want. Do note that if you want the reverse scenario (ISO 639-2 to ISO 639-1) it may not always work because while there should always be a mapping from an ISO 639-1 language code to ISO 639-2, the reverse is not guaranteed.The above should print out: