https://github.com/daun/statamic-graphql-alternate-locales
List alternate locales of entries in Statamic GraphQL queries
https://github.com/daun/statamic-graphql-alternate-locales
graphql i18n locale statamic
Last synced: 11 months ago
JSON representation
List alternate locales of entries in Statamic GraphQL queries
- Host: GitHub
- URL: https://github.com/daun/statamic-graphql-alternate-locales
- Owner: daun
- License: mit
- Created: 2024-10-03T20:35:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-13T10:48:58.000Z (over 1 year ago)
- Last Synced: 2025-05-03T05:37:56.634Z (about 1 year ago)
- Topics: graphql, i18n, locale, statamic
- Language: PHP
- Homepage:
- Size: 180 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Statamic GraphQL Alternate Locales
**List alternate locales of entries in Statamic GraphQL queries.**
This addon provides a simple way of querying alternate languages of entries in GraphQL. Mainly
useful for frontend language switches.

## Installation
```sh
composer require daun/statamic-graphql-alternate-locales
```
## Usage
After installation, you can list all locales of an entry from the new `locales` field. It requires
selecting the specific subfields to return. See below for a list of all supported subfields.
```graphql
{
page: entry(
collection: "pages"
slug: "about"
filter: { locale: "en" }
) {
slug
title
locale
locales {
locale
slug
title
}
}
}
```
The above query would result in the following data:
```json
{
"slug": "about",
"title": "About",
"locale": "en",
"locales": [
{
"locale": "de",
"slug": "ueber-uns",
"title": "Über uns"
},
{
"locale": "en",
"slug": "about",
"title": "About"
}
]
}
```
## Publish status
By default, the `locales` field only returns entries in published locales. To include all locales
regardless of publish status, set the `unpublished` arg to `true`:
```graphql
locales (unpublished: true) {
locale
slug
title
}
```
## Available subfields
| Subfield | Type | Value |
|---------------|---------------|---------------|
| `id` | `string` | `$entry->id()` |
| `locale` | `string` | `$entry->locale()` |
| `current` | `boolean` | `$entry->locale()` === `locale` filter of query |
| `slug` | `string` | `$entry->slug()` |
| `url` | `string` | `$entry->url()` |
| `uri` | `string` | `$entry->uri()` |
| `permalink` | `string` | `$entry->absoluteUrl()` |
| `published` | `boolean` | `$entry->published()` |
| `private` | `boolean` | `$entry->private()` |
| `status` | `string` | `$entry->status()` |
| `title` | `string` | `$entry->get('title')` |
## License
[MIT](https://opensource.org/licenses/MIT)