# General Translation Integrations: 翻訳をクエリする URL: https://generaltranslation.com/ja/docs/integrations/sanity/guides/querying-translations.mdx --- title: 翻訳をクエリする description: General Translation のドキュメント単位のローカライゼーション モデルを使用して、GROQ で翻訳された Sanity ドキュメントをクエリする方法。 related: links: - /docs/integrations/sanity/guides/translating-content - /docs/integrations/sanity/guides/managing-translations - /docs/integrations/sanity/guides/configuring-sanity --- General Translation は、Sanity の翻訳を個別のドキュメントとして保存し、それぞれに language フィールド (デフォルトは `language`) を付与します。 必要なバージョンは、そのフィールドで絞り込んでクエリします。既存のソース言語向けクエリもそのまま使えます。 ## ソースコンテンツをクエリする [#query-source] ソースドキュメントでは、デフォルトでは language フィールドが設定されないため、既存のソース向けクエリを変更する必要はありません。 ```text *[_type == "article"]{ title, slug, body } ``` ## 対象ロケールをクエリする [#query-locale] language フィールドでフィルタリングします。 ```text *[_type == "article" && language == "es"]{ title, slug, body } ``` ## 1 件の翻訳済みドキュメントをクエリする [#query-one] ```text *[_type == "article" && slug.current == "hello-world" && language == "es"][0]{ title, body } ``` 翻訳済みスラッグの重複を排除すると、スラッグには `hello-world-es` のようにロケールの接尾辞が付きます。 ## すべての言語版をクエリする [#query-all] ```text *[_type == "article"]{ title, slug, body, language } ``` ## source と翻訳を一緒にクエリする [#query-both] ソースドキュメントでは language フィールドが定義されていない場合があるため、source ロケールと未定義の値の両方を含めます。 ```text *[_type == "article" && (language == "en" || !defined(language))]{ title, slug, body } ``` ## カスタム language フィールドを使用する [#custom-field] プラグイン設定で `languageField: 'locale'` を指定している場合は、`language` ではなく `locale` をクエリしてください。schema フィールドとクエリ フィールドは、設定した値と一致している必要があります。 ```text *[_type == "article" && locale == "es"]{ title, slug, body } ``` ## 翻訳済みの参照をクエリする [#query-references] 参照にパッチが適用されると、翻訳済みドキュメントは参照先ドキュメントの翻訳版を指すようになります。あとは通常どおりクエリしてください。 ```text *[_type == "article" && language == "es"]{ title, "author": author->{ name, language } } ``` 参照の書き換え方法については、[参照へのパッチ適用](/docs/integrations/sanity/guides/managing-translations#patch-references)を参照してください。 ## Next steps - /docs/integrations/sanity/guides/translating-content - /docs/integrations/sanity/guides/managing-translations - /docs/integrations/sanity/guides/configuring-sanity