Skip to content

Get Locales

About

The getLocales query retrieves locale information from your store with support for pagination and detailed field access. This query is essential for:

  • Displaying available language and locale options
  • Building multi-language selector interfaces
  • Determining text direction (LTR/RTL) for UI layout
  • Retrieving locale-specific logos and branding
  • Managing store language configurations
  • Building locale management interfaces

The query supports cursor-based pagination and allows you to fetch all locales with full relationship access.

Arguments

ArgumentTypeRequiredDescription
firstInt❌ NoNumber of locales to retrieve from the start (forward pagination). Max: 100.
afterString❌ NoCursor to start after for forward pagination.
lastInt❌ NoNumber of locales to retrieve from the end (backward pagination). Max: 100.
beforeString❌ NoCursor to start before for backward pagination.

Possible Returns

FieldTypeDescription
edges[LocaleEdge!]!Array of locale edges containing locales and cursors.
edges.nodeLocale!The actual locale object with id, code, name, direction, and other fields.
edges.cursorString!Pagination cursor for this locale. Use with after or before arguments.
pageInfoPageInfo!Pagination metadata object.
pageInfo.hasNextPageBoolean!Whether more locales exist after the current page.
pageInfo.hasPreviousPageBoolean!Whether locales exist before the current page.
pageInfo.startCursorStringCursor of the first locale on the current page.
pageInfo.endCursorStringCursor of the last locale on the current page.
totalCountInt!Total number of locales available.

Locale Fields

FieldTypeDescription
idString!Unique identifier in format /api/shop/locales/{id}
_idInt!Numeric identifier for the locale
codeString!Unique locale code (e.g., "en", "ar", "fr", "de")
nameString!Display name of the locale (e.g., "English", "Arabic")
directionString!Text direction: "ltr" (left-to-right) or "rtl" (right-to-left)
logoPathStringFile path to the locale logo
logoUrlStringFull URL to the locale logo image

Common Use Cases

Display All Available Locales

graphql
query GetAllLocales {
  locales {
    edges {
      node {
        id
        code
        name
        direction
      }
    }
  }
}

Build Language Selector with Logos

graphql
query GetLocalesForSelector {
  locales {
    edges {
      node {
        code
        name
        logoUrl
        direction
      }
    }
  }
}

Get Locale with Complete Information

graphql
query GetLocalesWithDetails {
  locales {
    edges {
      node {
        id
        _id
        code
        name
        direction
        logoPath
        logoUrl 
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
    totalCount
  }
}

Get Locale Count and Pagination

graphql
query GetLocalesWithPagination($first: Int!) {
  locales(first: $first) {
    edges {
      cursor
      node {
        id
        code
        name
        direction
      }
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    totalCount
  }
}

Build Right-to-Left (RTL) Language List

graphql
query GetRTLLocales {
  locales {
    edges {
      node {
        code
        name
        direction
        logoUrl
      }
    }
  }
}

Error Handling

Missing Locales Configuration

json
{
  "data": {
    "locales": {
      "edges": [],
      "pageInfo": {
        "hasNextPage": false,
        "hasPreviousPage": false,
        "startCursor": null,
        "endCursor": null
      },
      "totalCount": 0
    }
  }
}

Invalid Pagination Parameters

json
{
  "errors": [
    {
      "message": "Argument \"first\" must be between 1 and 100"
    }
  ]
}

Invalid Cursor

json
{
  "errors": [
    {
      "message": "Invalid cursor provided"
    }
  ]
}

Best Practices

  1. Cache Locales - Locales change infrequently; implement client-side caching
  2. Use Direction Field - Always check the direction field for proper UI layout
  3. Request Only Needed Fields - Reduce payload by selecting specific fields
  4. Display Logo URLs - Use logoUrl for locale-specific branding in selectors
  5. Handle RTL/LTR - Use the direction field to apply appropriate CSS classes
  6. Paginate When Needed - For systems with many locales, use pagination
  7. Use Variables - Use GraphQL variables for dynamic locale queries

Released under the MIT License.