diff --git a/studio/lib/queries/i18n.ts b/studio/lib/queries/i18n.ts new file mode 100644 index 000000000..fdce669d3 --- /dev/null +++ b/studio/lib/queries/i18n.ts @@ -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} +`; diff --git a/studio/lib/queries/pages.ts b/studio/lib/queries/pages.ts index 2257ef5ff..784bd691b 100644 --- a/studio/lib/queries/pages.ts +++ b/studio/lib/queries/pages.ts @@ -1,37 +1,6 @@ import { groq } from "next-sanity"; -export const LANGUAGE_FIELD_FRAGMENT = groq` - "language": $language -`; - -export function translatedFieldFragment(fieldName: string) { - return groq`${fieldName}[_key == $language][0].value`; -} - -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} -`; +import { LANGUAGE_FIELD_FRAGMENT, TRANSLATED_LINK_FRAGMENT } from "./i18n"; const SECTIONS_FRAGMENT = groq` sections[]{ diff --git a/studio/lib/queries/siteSettings.ts b/studio/lib/queries/siteSettings.ts index 8bf907aff..ea7722032 100644 --- a/studio/lib/queries/siteSettings.ts +++ b/studio/lib/queries/siteSettings.ts @@ -2,10 +2,10 @@ import { groq } from "next-sanity"; import { LANGUAGE_FIELD_FRAGMENT, - PAGE_FRAGMENT, TRANSLATED_LINK_FRAGMENT, TRANSLATED_SLUG_VALUE_FRAGMENT, -} from "./pages"; +} from "./i18n"; +import { PAGE_FRAGMENT } from "./pages"; //Brand Assets export const BRAND_ASSETS_QUERY = groq` diff --git a/studio/lib/queries/slugTranslations.ts b/studio/lib/queries/slugTranslations.ts index 8f970a135..2e29fe621 100644 --- a/studio/lib/queries/slugTranslations.ts +++ b/studio/lib/queries/slugTranslations.ts @@ -1,6 +1,6 @@ import { groq } from "next-sanity"; -import { translatedFieldFragment } from "./pages"; +import { translatedFieldFragment } from "./utils/i18n"; export const SLUG_FIELD_TRANSLATIONS_FROM_LANGUAGE_QUERY = groq` *[${translatedFieldFragment("slug")} == $slug][0] { diff --git a/studio/lib/queries/specialPages.ts b/studio/lib/queries/specialPages.ts index fc8bd24b7..add8e9364 100644 --- a/studio/lib/queries/specialPages.ts +++ b/studio/lib/queries/specialPages.ts @@ -1,6 +1,6 @@ import { groq } from "next-sanity"; -import { translatedFieldFragment } from "./pages"; +import { translatedFieldFragment } from "./utils/i18n"; //Compensations export const COMPENSATIONS_PAGE_QUERY = groq` diff --git a/studio/lib/queries/utils/i18n.ts b/studio/lib/queries/utils/i18n.ts new file mode 100644 index 000000000..70e9ab300 --- /dev/null +++ b/studio/lib/queries/utils/i18n.ts @@ -0,0 +1,5 @@ +import { groq } from "next-sanity"; + +export function translatedFieldFragment(fieldName: string) { + return groq`${fieldName}[_key == $language][0].value`; +}