diff --git a/src/Field/NominatimSearch/NominatimSearch.tsx b/src/Field/NominatimSearch/NominatimSearch.tsx index ba41a22c18..0d34c8e09e 100644 --- a/src/Field/NominatimSearch/NominatimSearch.tsx +++ b/src/Field/NominatimSearch/NominatimSearch.tsx @@ -78,6 +78,12 @@ interface OwnProps { * Kingdom, de for Germany, etc. */ countryCodes: string; + /** + * Preferred language order for showing search results, overrides the value + * specified in the "Accept-Language" HTTP header. Either use a standard RFC2616 + * accept-language string or a simple comma-separated list of language codes. + */ + searchResultLanguage?: string; /** * The minimal amount of characters entered in the input to start a search. */ @@ -262,25 +268,59 @@ export class NominatimSearch extends React.Component response.json()) - .then(this.onFetchSuccess.bind(this)) - .catch(this.onFetchError.bind(this)); + try { + let fetchOpts: RequestInit = {}; + if (searchResultLanguage) { + fetchOpts = { + headers: { + 'accept-language': searchResultLanguage + } + }; + } + + const response = await fetch(`${nominatimBaseUrl}${getRequestParams}`, fetchOpts); + + if (!response.ok) { + throw new Error(`Return code: ${response.status}`); + } + + const responseJson = await response.json(); + + this.onFetchSuccess(responseJson); + } catch (e) { + this.onFetchError(e); + } } /** @@ -346,6 +386,7 @@ export class NominatimSearch extends React.Component