Skip to content

Get Single Locale

About

The locale query retrieves a single locale by ID with support for detailed field access. This query is essential for:

  • Fetching specific locale details for UI configuration
  • Checking text direction (LTR/RTL) for layout adjustments
  • Retrieving locale-specific branding and logos
  • Validating locale existence before operations
  • Building locale detail pages
  • Configuring locale-specific settings

The query allows you to fetch a specific locale with all its properties and relationships.

Arguments

ArgumentTypeRequiredDescription
idID!✅ YesThe unique identifier of the locale. Can be either numeric ID or IRI format (/api/shop/locales/{id}).

Possible Returns

FieldTypeDescription
localeLocaleThe requested locale object, or null if not found.

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 (e.g., "locales/en.png")

Common Use Cases

Get Locale Details by IRI ID

graphql
query GetLocaleByIRI($id: ID!) {
  locale(id: $id) {
    id
    _id
    code
    name
    direction
    logoPath
  }
}

Variables:

json
{
  "id": "/api/shop/locales/1"
}

Get Locale with Logo and Timestamps

graphql
query GetLocaleDetails($id: ID!) {
  locale(id: $id) {
    id
    code
    name
    direction
    logoPath
  }
}

Check If Locale is RTL

graphql
query GetLocaleDirection($id: ID!) {
  locale(id: $id) {
    code
    name
    direction
  }
}

Validate Locale Existence

graphql
query ValidateLocale($id: ID!) {
  locale(id: $id) {
    id
    code
  }
}

Error Handling

Locale Not Found

json
{
  "data": {
    "locale": null
  }
}

Missing Required ID Parameter

json
{
  "errors": [
    {
      "message": "Field \"locale\" argument \"id\" of type \"ID!\" is required but not provided."
    }
  ]
}

Invalid ID Format

json
{
  "errors": [
    {
      "message": "Invalid ID format. Expected IRI format like \"/api/shop/locales/1\" or numeric ID"
    }
  ]
}

Best Practices

  1. Always Provide ID - The ID parameter is required for this query
  2. Check for Null - Handle the case when locale is not found (returns null)
  3. Use Direction Field - Always check the direction field for proper UI layout
  4. Cache Results - Locales change infrequently; implement caching
  5. Validate Before Using - Verify locale exists before using in operations
  6. Use Variables - Use GraphQL variables for dynamic locale queries
  7. Request Needed Fields - Only request fields you'll actually use
  8. Handle RTL Properly - Apply appropriate CSS classes based on direction

Released under the MIT License.