-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(queries): extract reusable i18n query fragments
- Loading branch information
Showing
6 changed files
with
38 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { groq } from "next-sanity"; | ||
|
||
import { translatedFieldFragment } from "studio/lib/queries/utils/i18n"; | ||
|
||
export const LANGUAGE_FIELD_FRAGMENT = groq` | ||
"language": $language | ||
`; | ||
export const TRANSLATED_LINK_TITLE_FRAGMENT = groq` | ||
"linkTitle": ${translatedFieldFragment("linkTitle")} | ||
`; | ||
export const TRANSLATED_SLUG_VALUE_FRAGMENT = groq` | ||
select( | ||
slug._type == "slug" => slug.current, | ||
${translatedFieldFragment("slug")} | ||
) | ||
`; | ||
export const TRANSLATED_INTERNAL_LINK_FRAGMENT = groq` | ||
...select(linkType == "internal" => { | ||
"internalLink": internalLink->{ | ||
"_ref": ${TRANSLATED_SLUG_VALUE_FRAGMENT} | ||
} | ||
}) | ||
`; | ||
export const TRANSLATED_LINK_FRAGMENT = groq` | ||
${LANGUAGE_FIELD_FRAGMENT}, | ||
${TRANSLATED_LINK_TITLE_FRAGMENT}, | ||
${TRANSLATED_INTERNAL_LINK_FRAGMENT} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { groq } from "next-sanity"; | ||
|
||
export function translatedFieldFragment(fieldName: string) { | ||
return groq`${fieldName}[_key == $language][0].value`; | ||
} |