Mapping from locale to USB LANGID

982 views Asked by At

I am using libusb in a POSIXy environment (specifically FreeBSD but I hope to be fairly portable).

I want to fetch some strings from a USB device using libusb_get_string_descriptor but I'm not sure what value I should use for langid. I am aware of the official list from https://web.archive.org/web/20180829193331/http://www.usb.org/developers/docs/USB_LANGIDs.pdf/ but is there an easy way to map between the result of e.g. setlocale(LC_MESSAGES, NULL) and the LANGIDs in this PDF?

Is this even the correct approach? Sample code I have seen appear to all fetch the first string without worrying about language selection.

1

There are 1 answers

0
Benjamin Riggs On

I haven't been able to find any mapping like you've described, and I'm not sure anyone has made one, specifically because the language names aren't standard across OSes.

In my (admittedly limited) experience, devices tend to ignore the langid and will always return the same string for given index. However, I'm in the US and don't have access to equipment designed to support multiple languages, so this may not be true worldwide.

That said, every USB device (that support string descriptors at all) is required to provide at least one supported langid on string index zero, so you could grab that, first (with langid 0), to use as a default.