42
loading...
This website collects cookies to deliver better user experience
setLocale()
API on the client. This API allows you to manually set a user's locale. The best way to use this is to have a language selector somewhere in your application and to use the language List API to get a list of languages to show, then when a user selects a language call the setLocale()
API with the country code like so:sdk.setLocale('de'); // This will change the SDK locale to german
GET /v1/locale
returns a JSON Response like so:{
"ip": "127.0.0.1",
"countryCode": "US",
"country": "United States",
"continentCode": "NA",
"continent": "North America",
"eu": false,
"currency": "USD"
}
name
being in their own native language, how neat! Each of these also have their code
attached which you will be able to use to still determine which country the user is selecting. Using the countries list API is makes it so you have one less thing to think about when it comes to complex localization tasks. 🧠GET /v1/locale/countries/
returns a JSON Response like so:"sum": 194,
"countries": [
{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "Albania",
"code": "AL"
},
{
"name": "Algeria",
"code": "DZ"
},
...
]
GET /v1/locale/countries/eu
returns a JSON Response like so:{
"sum": 27,
"countries": [
{
"name": "Austria",
"code": "AT"
},
{
"name": "Belgium",
"code": "BE"
},
{
"name": "Croatia",
"code": "HR"
},
...
]
}
GET /v1/locale/countries/phones
returns a JSON Response like so:{
"sum": 194,
"phones": [
{
"code": "+1",
"countryCode": "CA",
"countryName": "Canada"
},
{
"code": "+1",
"countryCode": "US",
"countryName": "United States"
},
{
"code": "+7",
"countryCode": "RU",
"countryName": "Russia"
},
...
]
}
GET /v1/locale/currencies
returns a JSON Response like so:{
"sum": 117,
"currencies": [
{
"symbol": "$",
"name": "US Dollar",
"symbolNative": "$",
"decimalDigits": 2,
"rounding": 0,
"code": "USD",
"namePlural": "US dollars"
},
{
"symbol": "€",
"name": "Euro",
"symbolNative": "€",
"decimalDigits": 2,
"rounding": 0,
"code": "EUR",
"namePlural": "euros"
},
{
"symbol": "£",
"name": "British Pound Sterling",
"symbolNative": "£",
"decimalDigits": 2,
"rounding": 0,
"code": "GBP",
"namePlural": "British pounds sterling"
},
...
]
}
nativeName
attribute to each of the languages which will give you the language name in the native tongue of that language. For instance nativeName
will contain italiano
for Italian in a list it could be used to display it like: italian (italiano)
. Pretty neat right? This API enables you to show a language select for a user in their native language making it easier to select their one. All languages also have their code
which is ISO 639-1 so you can easily pass it into setLocale()
.GET /v1/locale/languages
returns a JSON Response like so:{
"sum": 185,
"languages": [
{
"name": "Afar",
"code": "aa",
"nativeName": "Afar"
},
{
"name": "Abkhazian",
"code": "ab",
"nativeName": "Аҧсуа"
},
{
"name": "Afrikaans",
"code": "af",
"nativeName": "Afrikaans"
},
{
"name": "Akan",
"code": "ak",
"nativeName": "Akana"
},
...
]
}
setLocale()
has been used or the X-Appwrite-Locale
header is set making this very easy to use for all HTTP Clients.42