Skip to content

Commit

Permalink
feat: add localization param #2
Browse files Browse the repository at this point in the history
Add localization param
  • Loading branch information
Amraneze authored Aug 2, 2024
2 parents 78c2f04 + 754579f commit c3a9b20
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/OpenStreetMapAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props {
placeholder?: string;
noOptionName?: string;
openStreetMapUrl?: string;
language?: string;
value: OpeenStreetMap | null;
classes?: OpenStreetMapAutocompleteStyle<string>;
styles?: OpenStreetMapAutocompleteStyle<CSSProperties>;
Expand Down Expand Up @@ -62,6 +63,7 @@ export function OpenStreetMapAutocomplete({
placeholder = 'Search',
noOptionName = 'No locations found',
openStreetMapUrl = 'https://nominatim.openstreetmap.org',
language = 'en',
}: Props) {
const [isActive, setActive] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -107,7 +109,7 @@ export function OpenStreetMapAutocomplete({
const getGeocoding = useCallback(
(address = '') => {
if (!address) return;
const url = `${openStreetMapUrl}/search?format=json&q=${address}`;
const url = `${openStreetMapUrl}/search?format=json&accept-language=${language}&q=${address}`;

fetch(url)
.then((response) => response.json())
Expand All @@ -123,7 +125,7 @@ export function OpenStreetMapAutocomplete({
)
.catch(() => setOptions([]));
},
[openStreetMapUrl]
[openStreetMapUrl, language]
);

useEffect(() => {
Expand Down

0 comments on commit c3a9b20

Please sign in to comment.