Return results in specified language (e.g. French)
Estimated reading time: 1 minuteThis example uses JawgPlaces.Input
to initialize a Jawg Places Input inside an HTML element on a webpage. It will force the return language of your results using lang
parameter from Jawg Places API.
By default, Jawg Places API returns results in the language of the user based on browser headers. You can change this behaviour and force a specific language.
Checkout all common options available on Jawg Places JS: JawgPlaces.JawgPlacesInputOptions.
You can also use a function
to set dynamicaly your language
.
let language = "fr";
new JawgPlaces.Input({
input: "#my-input",
language: () => language,
});
The value <YOUR_ACCESS_TOKEN>
in the <script>
tag must be replaced by your own access token from the Jawg Lab.
<html>
<head>
<script src="https://api.jawg.io/libraries/jawg-places@latest/jawg-places.js?access-token=<YOUR_ACCESS_TOKEN>"></script>
</head>
<body>
<input id="my-input" type="text" placeholder="Search" />
<script>
new JawgPlaces.Input({
input: '#my-input',
searchOnTyping: true,
// Language as a string
language: 'fr',
// Language as a function, can be change dynamically
// language: () => 'fr',
});
</script>
</body>
</html>