locales
Retrieve all published locales (languages) available in the store.
Query Structure
query {
locales {
id
code
name
nativeName
isPublished
}
}Arguments
| Argument | Type | Description | Required | Default |
|---|---|---|---|---|
| None | N/A | This query does not accept any arguments. | No | N/A |
Return Type
[Locale]
Localeobject fields:id(Int): Unique identifier of the locale.code(String): Locale code (e.g., “en-US”, “fr-FR”).name(String): English name of the locale.nativeName(String): Native name of the locale.isPublished(Boolean): Indicates if the locale is published and available in the store.
Examples
Basic Query
query {
locales {
id
code
name
}
}Advanced Query
query {
locales {
id
code
name
nativeName
isPublished
}
}Field Selection
query {
locales {
code
nativeName
}
}cURL Example
curl -X POST https://www.mystoreurl.com/graphql/0.8.0 \
-H "Content-Type: application/json" \
-d '{"query":"query { locales { id code name nativeName isPublished } }"}'JavaScript Example
async function fetchLocales() {
const endpoint = "https://www.mystoreurl.com/graphql/0.8.0";
const query = `
query {
locales {
id
code
name
nativeName
isPublished
}
}
`;
try {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ query })
});
if (!response.ok) {
throw new Error(`Network error: ${response.status} - ${response.statusText}`);
}
const { data, errors } = await response.json();
if (errors) {
console.error("GraphQL errors:", errors);
return null;
}
return data.locales;
} catch (error) {
console.error("Fetch error:", error);
return null;
}
}
// Usage example
fetchLocales().then(locales => {
if (locales) {
console.log("Available locales:", locales);
}
});Response Format
{
"data": {
"locales": [
{
"id": 1,
"code": "en-US",
"name": "English (United States)",
"nativeName": "English (United States)",
"isPublished": true
},
{
"id": 2,
"code": "fr-FR",
"name": "French (France)",
"nativeName": "Français (France)",
"isPublished": true
}
]
}
}Error Handling
| Error Code | Description | Possible Cause | Handling Recommendation |
|---|---|---|---|
| 400 | Bad Request | Malformed query or invalid syntax | Verify query syntax and structure |
| 500 | Internal Server Error | Server-side issue | Retry after some time or contact support |
| GraphQL Errors | Errors array returned in response | Query requested invalid fields or server validation failed | Inspect errors array for details and adjust query |
Performance Considerations
- The
localesquery returns a list of all published locales, which is typically a small dataset and fast to retrieve. - No arguments or filters are available, so the query always returns the full list.
- Cache the response on the client side to reduce repeated network calls, as locale data changes infrequently.
- Rate limiting may apply to the API; avoid excessive polling of this query.
- Use appropriate error handling and retries to handle transient network or server errors gracefully.
Authentication
This API currently does not require authentication. However, authentication requirements may be introduced in future versions. Monitor API updates for any changes to authentication requirements.
Related Types
Locale
| Field | Type | Description |
|---|---|---|
id | Int | Unique identifier of the locale. |
code | String | Locale code (e.g., “en-US”). |
name | String | English name of the locale. |
nativeName | String | Native name of the locale. |
isPublished | Boolean | Indicates if the locale is published. |
Notes
- The
localesquery provides essential information for internationalization and localization features. - Since no arguments are accepted, all published locales are always returned.
- Use the
isPublishedfield to filter locales client-side if needed. - Keep in mind that the API schema and available fields may evolve; always refer to the latest documentation.
Last updated on