Skip to Content

locales

Retrieve all published locales (languages) available in the store.

Query Structure

query { locales { id code name nativeName isPublished } }

Arguments

ArgumentTypeDescriptionRequiredDefault
NoneN/AThis query does not accept any arguments.NoN/A

Return Type

[Locale]

  • Locale object 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 CodeDescriptionPossible CauseHandling Recommendation
400Bad RequestMalformed query or invalid syntaxVerify query syntax and structure
500Internal Server ErrorServer-side issueRetry after some time or contact support
GraphQL ErrorsErrors array returned in responseQuery requested invalid fields or server validation failedInspect errors array for details and adjust query

Performance Considerations

  • The locales query 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.

Locale

FieldTypeDescription
idIntUnique identifier of the locale.
codeStringLocale code (e.g., “en-US”).
nameStringEnglish name of the locale.
nativeNameStringNative name of the locale.
isPublishedBooleanIndicates if the locale is published.

Notes

  • The locales query provides essential information for internationalization and localization features.
  • Since no arguments are accepted, all published locales are always returned.
  • Use the isPublished field 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