Querying translations | laravel-translatable-rust | Spatie       

 SPATIE  

laravel-translatable-rust
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-translatable-rust](https://spatie.be/docs/laravel-translatable-rust/v1)  Basic-usage  Querying translations

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-translatable-rust/v1) 

  Querying translations    
- [ Introduction ](https://spatie.be/docs/laravel-translatable-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-translatable-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-translatable-rust/v1/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-translatable-rust/v1/upgrading)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-translatable-rust/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-translatable-rust/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-translatable-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-translatable-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-translatable-rust/v1/about-us)

Basic usage
-----------

- [ Getting and setting translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/getting-and-settings-translations)
- [ Removing translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/removing-translations)
- [ Replacing translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/replacing-translations)
- [ Querying translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/querying-translations)
- [ Validating translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/validating-translations)
- [ Handling missing translations ](https://spatie.be/docs/laravel-translatable-rust/v1/basic-usage/handling-missing-translations)

Advanced usage
--------------

- [ Available events ](https://spatie.be/docs/laravel-translatable-rust/v1/advanced-usage/available-events)
- [ Serializing translations ](https://spatie.be/docs/laravel-translatable-rust/v1/advanced-usage/customize-the-toarray-method)
- [ Usage with factories ](https://spatie.be/docs/laravel-translatable-rust/v1/advanced-usage/usage-with-factories)

 Querying translations
=====================

`TranslationQuery` extends the real framework's `db::Builder<M>`. Scopes consume and return the builder, so filters run in SQL before pagination. There is no package-owned query object or in-memory post-filter.

```
use spatie_translatable::{Comparison, Translatable, TranslationQuery};
let settings = Translatable::default();
let english = NewsItem::query().where_locale("name", "en").get().await?;
let either = NewsItem::query().where_locales("name", &["en", "nl"]).get().await?;
let matching = NewsItem::query()
    .where_json_contains_locale("name", "en", "Hello", Comparison::Equal)
    .get().await?;
let page = NewsItem::query()
    .where_translation_like(&["name", "meta->description"], "book", Some(&["en", "nl"]), &settings)
    .order_by(NewsItem::id).paginate(10).page(2).await?;
```

- `where_locale` checks for a non-null raw JSON value, independently of read-side empty-string filtering.
- Multi-locale scopes OR their locales within one group. Separate calls AND their groups.
- Empty columns or locales match no rows.
- Comparisons accept native `IntoExpr` values such as `&str`, `i64`, and `bool`, not JSON-encoded strings. Values do not need to implement `Clone`. Numeric ordering stays numeric.
- `Comparison::Like` uses the framework's case-sensitive matcher; `LikeInsensitive` uses its ordinary `like` matcher.
- Search uses the latter with `%search%`; supplied `%` and `_` retain SQL LIKE wildcard meaning.
- With no explicit locales, search uses `settings.locales`, or `settings.locale` when that list is empty.

The framework validates identifiers and binds comparison/search values. Its JSON path syntax uses `->` and array selectors, so query locales must be application-approved language tags, not arbitrary object keys with path syntax. Ordinary tags such as `en`, `pt-BR`, and `zh_Hant` are supported. SQLite LIKE ignores ASCII case only; non-ASCII case must match. SQLite is the verified backend.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
