Skip to main content

ip-to-lang

ai-research-agent / search/ip-to-lang

Functions

getLanguageFromIP()

function getLanguageFromIP(ip): Promise<undefined | Object>

Retrieves language information for a given IP address using a remote API. Rate limit 45 req/min

You should first use Accept-Language header or navigator.language in front-end for user-set language https://stackoverflow.com/questions/673905/how-can-i-determine-a-users-locale-within-the-browser/31135571#31135571

Parameters

ParameterTypeDescription

ip

string

The IP address to look up.

Returns

Promise<undefined | Object>

A promise that resolves to an object containing country and language information, or undefined if not found.

returns.country - The name of the country.

returns.code - The two-letter country code.

returns.lang - The two-letter language code.

returns.language - The full name of the language.

returns.greeting - A greeting in the detected language.

Author

ai-research-agent (2024)

Variables

countryToLanguage

const countryToLanguage: object[];

Type declaration

NameTypeDefault value

code

string

"ad"

country

string

"Andorra"

lang

string

"es"