Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.57 KB

File metadata and controls

68 lines (51 loc) · 1.57 KB
description
LanguageCode Search Criterion

LanguageCode Criterion

The LanguageCode Search Criterion searches for content based on whether it's translated into the selected language.

Arguments

  • value - string(s) representing the language codes to search for
  • (optional) matchAlwaysAvailable - bool representing whether content with the alwaysAvailable flag should be returned even if it doesn't contain the selected language (default true)

Example

PHP

$query->query = new Criterion\LanguageCode('ger-DE', false);

REST API

=== "XML"

```xml
<Query>
    <Filter>
        <LanguageCodeCriterion>eng-GB</LanguageCodeCriterion>
    </Filter>
</Query>
```

=== "JSON"

```json
"Query": {
    "Filter": {
        "LanguageCodeCriterion": "eng-GB"
    }
}
```

Use case

You can use the LanguageCode Criterion to search for articles that are lacking a translation into a specific language:

$query = new LocationQuery;
$query->query = new Criterion\LogicalAnd([
    new Criterion\ContentTypeIdentifier('article'),
    new Criterion\LogicalNot(
        new Criterion\LanguageCode('ger-DE', false)
    )
    ]
);

$results = $this->searchService->findContent($query);
$articles = [];
foreach ($results->searchHits as $searchHit) {
    $articles[] = $searchHit;
}

return $this->render('list/articles_to_translate.html.twig', [
    'articles' => $articles,
]);