For your specific question, you can first convert the 3 letter ISO 4217 currency code to a 2 letter ISO 3166-1 alpha-2 country code and match the country code against a list of POSIX locales, recognizing that multiple locales with multiple languages may match.
For your more general question, why do you want to set the locale based on currency? One currency can map to many locales and languages, and also a person in a single locale may want to look at different currencies. While es_US
is a supported locale, there may be other combinations that are not. Would it not be better to have them set independently?
Mapping of Currency to Country Codes
To convert ISO 4217 currency codes to ISO 3166 country codes, you can use the Open Knowledge Foundation conversion tables referenced below which come in JSON and CSV format:
HTML: http://data.okfn.org/data/core/country-codes
JSON: http://data.okfn.org/data/core/country-codes/r/country-codes.json
CSV: https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv
POSIX Locales List
To convert ISO 3166 country codes to POSIX Locales, you can use a locale list to find locales with matching country codes. A list of locales is available in the following location on Linux systems:
/usr/share/i18n/SUPPORTED
This has also been posted to StackOverflow here:
List of All Locales and Their Short Codes?
More Information
ISO Currency Codes: http://www.iso.org/iso/home/standards/currency_codes.htm